Lightning.AuthProviders.Handler (Lightning v2.19.0-pre)
View SourceModule which wraps Oauth configuration and a WellKnown document into a convenient struct that can be used to authenticate users against any OIDC compliant provider.
Summary
Functions
Returns a Handler from a given AuthConfig
Create a new Provider struct, expects a name and opts
Verifies the id_token returned by the token endpoint and returns its claims.
Types
@type opts() :: [ client_id: String.t(), client_secret: String.t(), redirect_uri: String.t(), wellknown: Lightning.AuthProviders.WellKnown.t(), allow_unverified_email: boolean() ]
@type t() :: %Lightning.AuthProviders.Handler{ allow_unverified_email: boolean(), client: OAuth2.Client.t(), name: String.t(), wellknown: Lightning.AuthProviders.WellKnown.t() }
Functions
@spec from_model(model :: nil | Lightning.AuthProviders.AuthConfig.t()) :: {:ok, t()} | {:error, term()}
Returns a Handler from a given AuthConfig
@spec get_token(handler :: t(), code :: String.t()) :: {:ok, OAuth2.AccessToken.t()} | {:error, map() | atom()}
@spec get_userinfo(handler :: t(), token :: OAuth2.AccessToken.t()) :: map()
Create a new Provider struct, expects a name and opts:
:client_id- The providers issued id:client_secret- Secret for the client:redirect_uri- The URI for redirecting after authentication, usually the callback url in the router.:wellknown- A AuthProviders.WellKnown struct with the providers.well-known/openid-configuration.
@spec verify_id_token( handler :: t(), token :: OAuth2.AccessToken.t(), nonce :: String.t() | nil ) :: {:ok, map()} | {:error, term()}
Verifies the id_token returned by the token endpoint and returns its claims.
Checks the JWT signature against the provider's JWKS (asymmetric algs only),
then that iss matches the discovered issuer, aud contains our client id,
the token is not expired, and nonce matches the value we sent. This is what
lets the caller trust the token's identity claims (email, email_verified,
sub) rather than an unauthenticated userinfo response.