View Source Boruta.Oauth.Token (Boruta core v2.3.3)

OAuth access token and code schema and utilities

Summary

Functions

Determines if a token is valid, neither expired nor revoked.

Returns an hexadecimal SHA512 hash of given string

Determines if a token is revoked.

Types

@type t() :: %Boruta.Oauth.Token{
  client: Boruta.Oauth.Client.t() | nil,
  code_challenge: String.t() | nil,
  code_challenge_hash: String.t() | nil,
  code_challenge_method: String.t() | nil,
  expires_at: integer() | nil,
  inserted_at: DateTime.t() | nil,
  nonce: String.t() | nil,
  redirect_uri: String.t() | nil,
  refresh_token: String.t() | nil,
  refresh_token_revoked_at: DateTime.t() | nil,
  resource_owner: Boruta.Oauth.ResourceOwner.t() | nil,
  revoked_at: DateTime.t() | nil,
  scope: String.t(),
  state: String.t() | nil,
  sub: String.t() | nil,
  type: String.t(),
  value: String.t() | nil
}

Functions

Link to this function

ensure_valid(token, type \\ :access_token)

View Source
@spec ensure_valid(token :: t(), type :: :access_token | :refresh_token) ::
  :ok | {:error, String.t()}

Determines if a token is valid, neither expired nor revoked.

Examples

iex> ensure_valid(%Boruta.Oauth.Token{revoked_at: nil})
:ok

iex> ensure_valid(%Boruta.Oauth.Token{})
{:error, "Token revoked."}
Link to this function

expired?(token, type \\ :access_token, now \\ :os.system_time(:seconds))

View Source
@spec expired?(
  token :: t(),
  type :: :access_token | :refresh_token,
  now :: integer()
) :: boolean()

Determines if a token is expired

Examples

iex> expired?(%Boruta.Oauth.Token{expires_at: 1628260754})
false

iex> expired?(%Boruta.Oauth.Token{expires_at: 0}) # 1st january 1970
true
@spec hash(string :: String.t()) :: hashed_string :: String.t()

Returns an hexadecimal SHA512 hash of given string

Examples

iex> hash("foo")
"F7FBBA6E0636F890E56FBBF3283E524C6FA3204AE298382D624741D0DC6638326E282C41BE5E4254D8820772C5518A2C5A8C0C7F7EDA19594A7EB539453E1ED7"
@spec revoked?(token :: t(), type :: :access_token | :refresh_token) :: boolean()

Determines if a token is revoked.

Examples

iex> revoked?(%Boruta.Oauth.Token{revoked_at: nil})
:ok

iex> revoked?(%Boruta.Oauth.Token{})
false