View Source Kloak.Client (kloak v0.2.1)
Wrapper for building a properly configured OAuth2.Client
which can be used with Keycloak.
Configuration
config :kloak,
site: <KEYCLOAK_SITE_URL>
realm: <KEYCLOAK_REALM>
client_id: <KEYCLOAK_CLIENT_ID>
client_secret: <KEYCLOAK_CLIENT_SECRET>
Summary
Functions
Build a properly preconfigured OAuth2.Client
for communicating with Keycloak.
Fetches the user information of the authenticated user from the Keycloak userinfo endpoint.
The passed OAuth2.Client
must be properly configured and authorized to perform this action.
Functions
@spec new(keyword()) :: {:ok, OAuth2.Client.t()} | {:error, binary()}
Build a properly preconfigured OAuth2.Client
for communicating with Keycloak.
Examples
iex> new()
{:ok, %OAuth2.Client{}}
iex> new()
{:error, "Building the client failed due to an invalid configuration"}
iex> new()
{:error, "Building the client failed due to an error loading the configuration"}
iex> new(nil)
{:error, "Building the client failed due to invalid options"}
@spec user_information(OAuth2.Client.t()) :: {:ok, map()} | {:error, binary()}
Fetches the user information of the authenticated user from the Keycloak userinfo endpoint.
The passed OAuth2.Client
must be properly configured and authorized to perform this action.
Examples
iex> user_information(valid_client)
{:ok, %{"given_name" => "John", ...}}
iex> user_information(invalid_client)
{:error, "Fetching user information from Keycloak failed with an error"}
iex> user_information(invalid_client)
{:error, "Fetching user information failed due to an error loading the configuration"}
iex> user_information(nil)
{:error, "Fetching user information failed due to an invalid OAuth client"}