View Source oidcc_provider_configuration_worker (Oidcc v3.2.6)

OIDC Config Provider Worker

Loads and continuously refreshes the OIDC configuration and JWKs.

The worker supports reading values concurrently via an ETS table. To use this performance improvement, the worker has to be registered with a {local, Name}. No name / {global, Name} and {via, RegModule, ViaName} are not supported.

Summary

Types

Configuration Options

Functions

Get Parsed Jwks.

Refresh Configuration.

Refresh JWKs.

Refresh JWKs if the provided Kid is not matching any currently loaded keys.

Start Configuration Provider.

Types

-type opts() ::
          #{name => gen_server:server_name(),
            issuer := uri_string:uri_string(),
            provider_configuration_opts => oidcc_provider_configuration:opts(),
            backoff_min => oidcc_backoff:min(),
            backoff_max => oidcc_backoff:max(),
            backoff_type => oidcc_backoff:type()}.

Configuration Options

  • name - The gen_server name of the provider.
  • issuer - The issuer URI.
  • provider_configuration_opts - Options for the provider configuration fetching.
  • backoff_min - The minimum backoff interval in ms (default: 1_000).
  • backoff_max - The maximum backoff interval in ms (default: 30_000).
  • backoff_type - The backoff strategy, stop for no backoff and to stop, exponential for exponential, random for random, and random_exponential for random exponential (default: stop).

Functions

Link to this function

get_jwks(Name)

View Source (since 3.0.0)
-spec get_jwks(Name :: gen_server:server_ref()) -> jose_jwk:key() | undefined.

Get Parsed Jwks.

Link to this function

get_provider_configuration(Name)

View Source (since 3.0.0)
-spec get_provider_configuration(Name :: gen_server:server_ref()) ->
                                    oidcc_provider_configuration:t() | undefined.

Get Configuration.

Link to this function

refresh_configuration(Name)

View Source (since 3.0.0)
-spec refresh_configuration(Name :: gen_server:server_ref()) -> ok.

Refresh Configuration.

Examples

{ok, Pid} =
  oidcc_provider_configuration_worker:start_link(#{
    issuer => <<"https://accounts.google.com">>
  }).

%% Later

oidcc_provider_configuration_worker:refresh_configuration(Pid).
Link to this function

refresh_jwks(Name)

View Source (since 3.0.0)
-spec refresh_jwks(Name :: gen_server:server_ref()) -> ok.

Refresh JWKs.

Examples

{ok, Pid} =
  oidcc_provider_configuration_worker:start_link(#{
    issuer => <<"https://accounts.google.com">>
  }).

%% Later

oidcc_provider_configuration_worker:refresh_jwks(Pid).
Link to this function

refresh_jwks_for_unknown_kid(Name, Kid)

View Source (since 3.0.0)
-spec refresh_jwks_for_unknown_kid(Name :: gen_server:server_ref(), Kid :: binary()) -> ok.

Refresh JWKs if the provided Kid is not matching any currently loaded keys.

Examples

{ok, Pid} =
  oidcc_provider_configuration_worker:start_link(#{
    issuer => <<"https://accounts.google.com">>
  }).

oidcc_provider_configuration_worker:refresh_jwks_for_unknown_kid(Pid, <<"kid">>).
Link to this function

start_link(Opts)

View Source (since 3.0.0)
-spec start_link(Opts :: opts()) -> gen_server:start_ret().

Start Configuration Provider.

Examples

{ok, Pid} =
  oidcc_provider_configuration_worker:start_link(#{
    issuer => <<"https://accounts.google.com">>,
    name => {local, google_config_provider}
  }).
%% ...
-behaviour(supervisor).

%% ...

init(_opts) ->
  SupFlags = #{strategy => one_for_one, intensity => 1, period => 5},
  ChildSpecs = [#{id => google_config_provider,
    start => {oidcc_provider_configuration_worker,
              start_link,
              [
                #{issuer => <<"https://accounts.google.com">>}
              ]},
    restart => permanent,
    type => worker,
    modules => [oidcc_provider_configuration_worker]}],
  {ok, {SupFlags, ChildSpecs}}.