# `Lightning.AuthProviders.Handler`
[🔗](https://github.com/OpenFn/lightning/blob/main/lib/lightning/auth_providers/handler.ex#L1)

Module which wraps Oauth configuration and a WellKnown document
into a convenient struct that can be used to authenticate users against
any OIDC compliant provider.

# `opts`

```elixir
@type opts() :: [
  client_id: String.t(),
  client_secret: String.t(),
  redirect_uri: String.t(),
  wellknown: Lightning.AuthProviders.WellKnown.t(),
  allow_unverified_email: boolean()
]
```

# `t`

```elixir
@type t() :: %Lightning.AuthProviders.Handler{
  allow_unverified_email: boolean(),
  client: OAuth2.Client.t(),
  name: String.t(),
  wellknown: Lightning.AuthProviders.WellKnown.t()
}
```

# `authorize_url`

```elixir
@spec authorize_url(handler :: t(), state :: String.t(), nonce :: String.t()) ::
  String.t()
```

# `from_model`

```elixir
@spec from_model(model :: nil | Lightning.AuthProviders.AuthConfig.t()) ::
  {:ok, t()} | {:error, term()}
```

Returns a Handler from a given AuthConfig

# `get_token`

```elixir
@spec get_token(handler :: t(), code :: String.t()) ::
  {:ok, OAuth2.AccessToken.t()} | {:error, map() | atom()}
```

# `get_userinfo`

```elixir
@spec get_userinfo(handler :: t(), token :: OAuth2.AccessToken.t()) :: map()
```

# `new`

```elixir
@spec new(name :: String.t(), opts :: opts()) :: {:ok, t()} | {:error, term()}
```

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`.

# `verify_id_token`

```elixir
@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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
