View Source Oidcc.ClientContext (Oidcc v3.2.6)

Client Configuration for authorization, token exchange and userinfo

For most projects, it makes sense to use Oidcc.ProviderConfiguration.Worker and the high-level interface of Oidcc. In that case direct usage of this module is not needed.

Summary

Types

Link to this type

authenticated_t()

View Source (since 3.0.0)
@type authenticated_t() :: %Oidcc.ClientContext{
  client_id: String.t(),
  client_jwks: JOSE.JWK.t() | :none,
  client_secret: String.t(),
  jwks: JOSE.JWK.t(),
  provider_configuration: Oidcc.ProviderConfiguration.t()
}
@type t() :: authenticated_t() | unauthenticated_t()
Link to this type

unauthenticated_t()

View Source (since 3.0.0)
@type unauthenticated_t() :: %Oidcc.ClientContext{
  client_id: String.t(),
  client_jwks: :none,
  client_secret: :unauthenticated,
  jwks: JOSE.JWK.t(),
  provider_configuration: Oidcc.ProviderConfiguration.t()
}

Functions

Link to this function

apply_profiles(client_context, opts)

View Source (since 3.2.0)
@spec apply_profiles(t(), :oidcc_profile.opts()) ::
  {:ok, t(), :oidcc_profile.opts_no_profiles()}
  | {:error, :oidcc_client_context.error()}

Apply OpenID Connect / OAuth2 Profiles to the context

See :oidcc_client_context.apply_profiles/2 for more.

Examples

iex> {:ok, _pid} =
...>   Oidcc.ProviderConfiguration.Worker.start_link(%{
...>   issuer: "https://accounts.google.com",
...>   name: __MODULE__.GoogleConfigProvider
...> })
...>
...> {:ok, client_context} =
...>   Oidcc.ClientContext.from_configuration_worker(
...>     __MODULE__.GoogleConfigProvider,
...>     "client_id",
...>     "client_Secret"
...>   )
...>
...> {:ok, %Oidcc.ClientContext{}, %{}} =
...>   Oidcc.ClientContext.apply_profiles(
...>     client_context,
...>     %{profiles: [:fapi2_message_signing]}
...>   )
Link to this function

from_configuration_worker(provider_name, client_id, client_secret, opts \\ %{})

View Source (since 3.0.0)
@spec from_configuration_worker(
  provider_name :: GenServer.name(),
  client_id :: String.t(),
  client_secret :: String.t(),
  opts :: :oidcc_client_context.authenticated_opts()
) :: {:ok, authenticated_t()} | {:error, :oidcc_client_context.error()}
@spec from_configuration_worker(
  provider_name :: GenServer.name(),
  client_id :: String.t(),
  client_secret :: :unauthenticated,
  opts :: :oidcc_client_context.unauthenticated_opts()
) :: {:ok, unauthenticated_t()} | {:error, :oidcc_client_context.error()}

Create Client Context from a Oidcc.ProviderConfiguration.Worker

Examples

iex> {:ok, pid} =
...>   Oidcc.ProviderConfiguration.Worker.start_link(%{
...>   issuer: "https://accounts.google.com",
...>   name: __MODULE__.GoogleConfigProvider
...> })
...>
...> {:ok, %Oidcc.ClientContext{}} =
...>   Oidcc.ClientContext.from_configuration_worker(
...>     __MODULE__.GoogleConfigProvider,
...>     "client_id",
...>     "client_Secret"
...>   )
...>
...> {:ok, %Oidcc.ClientContext{}} =
...>   Oidcc.ClientContext.from_configuration_worker(
...>     pid,
...>     "client_id",
...>     "client_Secret",
...>     %{client_jwks: JOSE.JWK.generate_key(16)}
...>   )
Link to this function

from_manual(configuration, jwks, client_id, client_secret, opts \\ %{})

View Source (since 3.0.0)
@spec from_manual(
  configuration :: Oidcc.ProviderConfiguration.t(),
  jwks :: JOSE.JWK.t(),
  client_id :: String.t(),
  client_secret :: String.t(),
  opts :: :oidcc_client_context.authenticated_opts()
) :: authenticated_t()
@spec from_manual(
  configuration :: Oidcc.ProviderConfiguration.t(),
  jwks :: JOSE.JWK.t(),
  client_id :: String.t(),
  client_secret :: :unauthenticated,
  opts :: :oidcc_client_context.unauthenticated_opts()
) :: unauthenticated_t()

Create Client Context manually

Examples

iex> {:ok, {configuration, _expiry}} =
...>   Oidcc.ProviderConfiguration.load_configuration(
...>     "https://login.salesforce.com"
...>   )
...>
...> {:ok, {jwks, _expiry}} =
...>   Oidcc.ProviderConfiguration.load_jwks(
...>     configuration.jwks_uri
...>   )
...>
...> %Oidcc.ClientContext{} =
...>   Oidcc.ClientContext.from_manual(
...>     configuration,
...>     jwks,
...>     "client_id",
...>     "client_Secret",
...>     %{client_jwks: JOSE.JWK.generate_key(16)}
...>   )