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

Note: expires_in is seconds till expiry from time of issue

pub type AccessToken {
  AccessToken(
    access_token: String,
    refresh_token: Option(String),
    expires_in: Option(Int),
    token_type: String,
  )
}

Constructors

  • AccessToken(
      access_token: String,
      refresh_token: Option(String),
      expires_in: Option(Int),
      token_type: String,
    )

Functions

pub fn decoder() -> fn(Dynamic) ->
  Result(AccessToken, List(DecodeError))

Decode an access token, only considering typical fields of

  • access_token
  • refresh_token (optional)
  • expires (optional) - seconds till expiry from now
  • token_type (optional) - typically “Bearer”

TODO: Seems like “expires_in” is also possible for “expires”.

TODO: Decode with current datetime to give future expires_in.

TODO: Any other params are possible, so should be returned as a map.

pub fn has_an_expiry(access_token: AccessToken) -> Bool

Does the access token have an expiry?

Returns true unless expires_in 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.

pub fn normalize_token_type(token_type: Option(String)) -> String