View Source Assent.JWTAdapter behaviour (Assent v0.2.10)

JWT adapter helper module.

You can configure the JWT adapter by updating the configuration:

jwt_adapter: {Assent.JWTAdapter.AssentJWT, [...]}

Default options can be set by passing a list of options:

jwt_adapter: {Assent.JWTAdapter.AssentJWT, [...]}

You can also set global application config:

config :assent, :jwt_adapter, Assent.JWTAdapter.AssentJWT

Usage

defmodule MyApp.MyJWTAdapter do
  @behaviour Assent.JWTAdapter

  @impl true
  def sign(claims, alg, secret, opts) do
    # ...
  end

  @impl true
  def verify(token, secret, opts) do
    # ...
  end
end

Summary

Functions

Loads a private key from the provided configuration

Generates a signed JSON Web Token signature

Verifies the JSON Web Token signature

Callbacks

Link to this callback

sign(map, binary, binary, t)

View Source
@callback sign(map(), binary(), binary(), Keyword.t()) ::
  {:ok, binary()} | {:error, term()}
@callback verify(binary(), binary() | map() | nil, Keyword.t()) ::
  {:ok, map()} | {:error, term()}

Functions

Link to this function

load_private_key(config)

View Source
@spec load_private_key(Assent.Config.t()) :: {:ok, binary()} | {:error, term()}

Loads a private key from the provided configuration

Link to this function

sign(claims, alg, secret, opts \\ [])

View Source
@spec sign(map(), binary(), binary(), Keyword.t()) ::
  {:ok, binary()} | {:error, term()}

Generates a signed JSON Web Token signature

Link to this function

verify(token, secret, opts \\ [])

View Source
@spec verify(binary(), binary() | map() | nil, Keyword.t()) ::
  {:ok, map()} | {:error, any()}

Verifies the JSON Web Token signature