Ingot.Auth.OIDC (Ingot v0.1.0)
View SourceOpenID Connect (OIDC) authentication provider.
Supports multiple OIDC providers including Auth0, Okta, and Keycloak. This is a stub implementation suitable for testing and development. Production deployments should integrate with a real OIDC library.
Configuration
OIDC configuration should include:
config = %{
provider: "https://auth.example.com",
client_id: "your_client_id",
client_secret: "your_client_secret",
redirect_uri: "https://your-app.com/auth/callback",
scopes: ["openid", "email", "profile"]
}Supported Providers
- Auth0 (auth0.com)
- Okta (okta.com)
- Keycloak (keycloak.org)
- Generic OIDC-compliant providers
Examples
# Generate authorization URL
config = %{provider: "https://auth.example.com", client_id: "client_123", ...}
url = OIDC.authorization_url(config, "random_state")
# Exchange authorization code for tokens
{:ok, tokens} = OIDC.exchange_code(config, "auth_code_123")
# Verify and extract claims from ID token
{:ok, claims} = OIDC.verify_id_token(config, tokens["id_token"])
Summary
Functions
Generate OIDC authorization URL.
Exchange authorization code for tokens.
Get provider-specific endpoint configurations.
Verify ID token and extract claims.
Types
Functions
Generate OIDC authorization URL.
Returns a URL that the user should be redirected to for authentication.
Parameters
config- OIDC configuration mapstate- Random state parameter for CSRF protection
Examples
iex> config = %{provider: "https://auth.example.com", client_id: "client_123", redirect_uri: "https://app/callback", scopes: ["openid"]}
iex> url = OIDC.authorization_url(config, "state_xyz")
iex> String.contains?(url, "client_id=client_123")
true
@spec exchange_code(config(), String.t()) :: {:ok, token_response()} | {:error, atom()}
Exchange authorization code for tokens.
This is a stub implementation that returns mock tokens. In production, this would make an HTTP request to the token endpoint.
Parameters
config- OIDC configuration mapcode- Authorization code from callback
Examples
iex> config = %{provider: "https://auth.example.com", client_id: "client_123", client_secret: "secret", redirect_uri: "https://app/callback"}
iex> {:ok, tokens} = OIDC.exchange_code(config, "auth_code_123")
iex> Map.has_key?(tokens, "access_token")
true
Get provider-specific endpoint configurations.
Returns a map of known OIDC providers and their endpoint URLs.
Examples
iex> configs = OIDC.provider_configs()
iex> Map.has_key?(configs, :auth0)
true
Verify ID token and extract claims.
This is a stub implementation that returns mock claims. In production, this would verify the JWT signature and extract claims.
Parameters
config- OIDC configuration mapid_token- ID token from token response
Examples
iex> config = %{provider: "https://auth.example.com"}
iex> {:ok, claims} = OIDC.verify_id_token(config, "mock.jwt.token")
iex> Map.has_key?(claims, "sub")
true