Boruta.Oauth.Token (Boruta core v1.2.1) 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.
Determines if a token is expired
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
Specs
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 SourceSpecs
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
Returns an hexadecimal SHA512 hash of given string
Examples
iex> hash("foo")
"F7FBBA6E0636F890E56FBBF3283E524C6FA3204AE298382D624741D0DC6638326E282C41BE5E4254D8820772C5518A2C5A8C0C7F7EDA19594A7EB539453E1ED7"
Specs
Determines if a token is revoked.
Examples
iex> revoked?(%Boruta.Oauth.Token{revoked_at: nil})
:ok
iex> revoked?(%Boruta.Oauth.Token{})
false