Boruta.Oauth.Token (Boruta core v1.2.0) View Source

Token schema. Representing both access tokens and codes.

Link to this section 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.

Link to this section Types

Specs

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

Link to this section Functions

Link to this function

ensure_valid(token, type \\ :access_token)

View Source

Specs

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

Specs

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

Specs

hash(string :: String.t()) :: hashed_string :: String.t()

Returns an hexadecimal SHA512 hash of given string

Examples

iex> hash("foo")
"F7FBBA6E0636F890E56FBBF3283E524C6FA3204AE298382D624741D0DC6638326E282C41BE5E4254D8820772C5518A2C5A8C0C7F7EDA19594A7EB539453E1ED7"

Specs

revoked?(token :: t()) :: boolean()

Determines if a token is revoked.

Examples

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

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