View Source oidcc_cowboy_load_userinfo (oidcc_cowboy v2.0.0-alpha.3)

Validate extracted authorization token using userinfo retrieval.

See: https://openid.net/specs/openid-connect-core-1_0.html#UserInfo

This middleware should be used together with oidcc_cowboy_extract_authorization.

This middleware will send a userinfo request for ever request. To avoid this, provide a cache to opts().

Usage

  OidccCowboyOpts = #{
      provider => openid_confi_provider_name,
      client_id => <<"client_id">>,
      client_secret => <<"client_secret">>
  },
  Dispatch = cowboy_router:compile([
      {'_', [
          %% ...
      ]}
  ]),
  {ok, _} = cowboy:start_clear(http, [{port, 8080}], #{
      middlewares => [
          oidcc_cowboy_extract_authorization,
          oidcc_cowboy_load_userinfo,
          cowboy_router,
          cowboy_handler
      ],
      env => #{
          dispatch => Dispatch,
          oidcc_cowboy_load_userinfo => OidccCowboyOpts
      }
  })

Summary

Types

Options for the middleware

Types

Link to this type

opts/0

View Source (since 2.0.0 -------------------------------------------------------------------)
-type opts() ::
    #{provider := gen_server:server_ref(),
      client_id := binary(),
      client_secret := binary(),
      userinfo_retrieve_opts => oidcc_userinfo:retrieve_opts(),
      cache => oidcc_cowboy_cache:t(),
      send_inactive_token_response =>
          fun((Req :: cowboy_req:req(), Env :: cowboy_middleware:env()) ->
                  {ok, cowboy_req:req(), cowboy_middleware:env()} | {stop, cowboy_req:req()})}.

Options for the middleware

Options

  • provider - name of the oidcc_provider_configuration_worker
  • client_id - OAuth Client ID to use for the userinfo retrieval
  • client_secret - OAuth Client Secret to use for the userinfo retrieval
  • userinfo_retrieve_opts - Options to pass to userinfo loading
  • send_inactive_token_response - Customize Error Response for inactive token
  • cache - Cache userinfo response - See oidcc_cowboy_cache