UeberauthToken (ueberauth_token v0.2.0-dev)
A package for authenticating with an oauth2 token and building an ueberauth struct.
Features:
- Cache the ueberauth struct response using the excellent
whitfin/cachex
library. - Perform asynchronyous validity checks for each token key in the cache.
See full description of the config options can be found in UeberauthToken.Config
@moduledoc.
defining-an-provider-module
Defining an provider module
An provider module must be provided in order for UeberauthToken to function correctly. The provider
implements the callbacks specified in the module UeberauthToken.Strategy
. Read more about the
requirements for the provider in UeberauthToken.Strategy
.
Read more on basic usage in the UeberauthToken.Strategy
module.
Link to this section Summary
Functions
Execute token validation for an oauth2 bearer token against a given oauthorization server (provider).
Link to this section Functions
token_auth(token, provider, opts \\ [validate_provider: true])
@spec token_auth(token :: String.t(), provider :: module(), opts :: list()) :: {:ok, Ueberauth.Auth.t()} | {:error, Ueberauth.Failure.t()}
Execute token validation for an oauth2 bearer token against a given oauthorization server (provider).
This function may be useful when a token needs to be validated by a resource server
and the validation is taking place outside a Plug
pipeline. For example, in
a web socket connection.
options
Options
* `:validate_provider` - boolean
Defaults to `true`. Validates that the provider has already been configured
in the application configuration. It is recommended to set this
value to `[validate_provider: false]` once it is known that the application
is correctly configured to reduce the runtime burden of checking the
configuration on each token validation event.
example-usage
Example usage
@provider UeberauthToken.TestProvider
def connect(%{"authorization" => token} = params, socket) do
case UeberauthToken.token_auth(token, @provider) do
{:ok, %Ueberauth.Auth{} = auth} ->
{:ok, assign(socket, :user_id, auth.uid)}
{:error, %Ueberauth.Failure{} = failure} ->
{:error, failure}
end
end