glow_auth/access_token
An access token is just a string, but it typically expires.
Depending on the type of grant, it may be refreshable via a separate refresh token, or by directly requesting a new access token.
…the intention is to generate this from the response given when sending a token request.
Types
Represents a token returned from an oauth2 provider
pub type AccessToken {
AccessToken(
access_token: String,
refresh_token: Option(String),
expires_at: Option(Int),
token_type: String,
)
}
Constructors
-
AccessToken( access_token: String, refresh_token: Option(String), expires_at: Option(Int), token_type: String, )
Functions
pub fn expires(access_token: AccessToken) -> Bool
This is basically a decode from json blob returned from oauth Determines if the access token will expire or not.
Returns true
unless expires_at
is None
.
pub fn is_expired(access_token: AccessToken) -> Bool
Determines if the access token has expired.
pub fn new(token: String) -> AccessToken
Returns a new AccessToken
given the access token string
or a response map
.
Note if giving a map, please be sure to make the key a string
no an atom
.
This is used by OAuth2.Client.get_token/4
to create the OAuth2.AccessToken
struct.
Example
iex> OAuth2.AccessToken.new("abc123")
%OAuth2.AccessToken{access_token: "abc123", expires_at: nil, other_params: %{}, refresh_token: nil, token_type: "Bearer"}
iex> OAuth2.AccessToken.new(%{"access_token" => "abc123"})
%OAuth2.AccessToken{access_token: "abc123", expires_at: nil, other_params: %{}, refresh_token: nil, token_type: "Bearer"}
pub fn normalize_token_type(token_type: Option(String)) -> String