Packages
boruta
0.1.0-rc.4
3.0.0-beta.4
3.0.0-beta.3
3.0.0-beta.2
3.0.0-beta.1
2.3.6
2.3.5
2.3.4
2.3.3
2.3.2
2.3.1
2.3.0
2.2.2
2.2.1
2.2.0
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.1
2.0.0
2.0.0-rc.1
2.0.0-rc.0
1.2.1
1.2.0
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0
1.0.0-rc.3
1.0.0-rc.2
1.0.0-rc.1
1.0.0-rc.0
0.2.1
0.2.0
0.1.1
0.1.0
0.1.0-rc.5
0.1.0-rc.4
0.1.0-rc.3
0.1.0-rc.2
0.1.0-rc.1
Core of an OAuth/OpenID Connect provider enabling authorization in your applications.
Current section
Files
Jump to
Current section
Files
lib/boruta/oauth/schemas/token.ex
defmodule Boruta.Oauth.Token do
@moduledoc """
Token schema. Representing both access tokens and codes.
"""
alias Boruta.Oauth.Token
defstruct [
id: nil,
type: nil,
value: nil,
state: nil,
scope: nil,
redirect_uri: nil,
expires_at: nil,
client: nil,
resource_owner: nil,
refresh_token: nil,
inserted_at: nil
]
@type t :: %__MODULE__{
type: String.t(),
value: String.t(),
state: String.t(),
scope: String.t(),
redirect_uri: String.t(),
expires_at: integer(),
client: Boruta.Oauth.Client.t(),
resource_owner: struct(),
refresh_token: String.t(),
inserted_at: DateTime.t()
}
@doc """
Determines if a token is expired
## Examples
iex> expired?(%Boruta.Oauth.Token{expires_at: 1638316800}) # 1st january 2021
:ok
iex> expired?(%Boruta.Oauth.Token{expires_at: 0}) # 1st january 1970
{:error, "Token expired."}
"""
# TODO move this out of the schema
@spec expired?(%Token{expires_at: integer()}) :: :ok | {:error, any()}
def expired?(%Token{expires_at: expires_at}) do
case :os.system_time(:seconds) < expires_at do
true -> :ok
false -> {:error, "Token expired."}
end
end
end