WardrikOAuth.Token (wardrik_oauth v0.1.0-rc.1)

Copy Markdown

A token an authorization server granted. Kept in the vault as JSON.

Summary

Types

t()

An access token and what came with it.

Functions

Copies old's refresh token into new if new has none.

Decodes a token from JSON.

Encodes the token as JSON.

Marks the token expired, so the next use refreshes it.

Returns whether the token is valid for more than 30 more seconds.

Reads a token endpoint's response. Returns the token, or the error it holds.

Returns whether the token can be refreshed.

Types

t()

@type t() :: %WardrikOAuth.Token{
  access_token: String.t(),
  expires_at: integer() | nil,
  refresh_token: String.t() | nil,
  scope: String.t() | nil,
  token_endpoint: String.t()
}

An access token and what came with it.

Functions

carry_refresh(new, old)

@spec carry_refresh(t(), t()) :: t()

Copies old's refresh token into new if new has none.

decode(json)

@spec decode(String.t()) :: {:ok, t()} | {:error, :unreadable}

Decodes a token from JSON.

encode(token)

@spec encode(t()) :: String.t()

Encodes the token as JSON.

expire(token)

@spec expire(t()) :: t()

Marks the token expired, so the next use refreshes it.

fresh?(token)

@spec fresh?(t()) :: boolean()

Returns whether the token is valid for more than 30 more seconds.

from_response(status, body, token_endpoint)

@spec from_response(pos_integer(), map(), String.t()) :: {:ok, t()} | {:error, term()}

Reads a token endpoint's response. Returns the token, or the error it holds.

renewable?(token)

@spec renewable?(t()) :: boolean()

Returns whether the token can be refreshed.