View Source oidcc_cowboy_callback (oidcc_cowboy v2.0.0)

Cowboy Oidcc Callback Handler

Usage

  OidccCowboyOpts = #{
      provider => config_provider_gen_server_name,
      client_id => <<"client_id">>,
      client_secret => <<"client_secret">>,
      redirect_uri => "http://localhost/oidc/return"
  },
  OidccCowboyCallbackOpts = maps:merge(OidccCowboyOpts, #{
      handle_success => fun(Req, _Token, #{<<"sub">> := Subject}) ->
          cowboy_req:reply(200, #{}, ["Hello ", Subject, "!"], Req)
      end
  }),
  Dispatch = cowboy_router:compile([
      {'_', [
          {"/", oidcc_cowboy_authorize, OidccCowboyOpts},
          {"/oidc/return", oidcc_cowboy_callback, OidccCowboyCallbackOpts}
      ]}
  ]),
  {ok, _} = cowboy:start_clear(http, [{port, 8080}], #{
      env => #{dispatch => Dispatch}
  })

Summary

Types

Configure Token Retrieval

Types

Link to this type

error/0

View Source (since 2.0.0 -------------------------------------------------------------------)
-type error() ::
    oidcc_client_context:error() |
    oidcc_token:error() |
    oidcc_userinfo:error() |
    useragent_mismatch | peer_ip_mismatch |
    {missing_request_param, Param :: binary()}.
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(),
      redirect_uri := uri_string:uri_string(),
      check_useragent => boolean(),
      check_peer_ip => boolean(),
      retrieve_userinfo => boolean(),
      request_opts => oidcc_http_util:request_opts(),
      handle_success :=
          fun((Req :: cowboy_req:req(),
               Token :: oidcc_token:t(),
               Userinfo :: oidcc_jwt_util:claims() | undefined) ->
                  cowboy_req:req()),
      handle_failure => fun((Req :: cowboy_req:req(), Reason :: error()) -> cowboy_req:req())}.

Configure Token Retrieval

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

Parameters

  • provider - name of the running oidcc_provider_configuration_worker
  • client_id - Client ID
  • client_secret - Client Secret
  • redirect_uri - redirect target after authorization is completed
  • check_useragent - check if useragent is the same as before the authorization request
  • check_peer_ip - check if the client IP is the same as before the authorization request
  • retrieve_userinfo - whether to load userinfo from the provider
  • request_opts - request opts for http calls to provider
  • handle_success - handler to react to successful token retrieval (render response etc.)
  • handle_failure - handler to react to errors (render response etc.)