View Source oidcc_cowboy_callback (oidcc_cowboy v2.0.0-alpha.2)
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
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 runningoidcc_provider_configuration_worker
client_id
- Client IDclient_secret
- Client Secretredirect_uri
- redirect target after authorization is completedcheck_useragent
- check if useragent is the same as before the authorization requestcheck_peer_ip
- check if the client IP is the same as before the authorization requestretrieve_userinfo
- whether to load userinfo from the providerrequest_opts
- request opts for http calls to providerhandle_success
- handler to react to successful token retrieval (render response etc.)handle_failure
- handler to react to errors (render response etc.)