DomainConnect.Token (DomainConnect v0.5.0)

Copy Markdown View Source

An OAuth access token issued by a DNS provider during the asynchronous Domain Connect flow.

Returned by DomainConnect.async_token/2 and DomainConnect.async_refresh/2. :expires_at is computed from :expires_in and the issue time so callers can check expired?/2 without re-deriving it.

Summary

Functions

Whether the token is expired at now (unix seconds). A token with no expiry is treated as not expired.

Builds a Token from a decoded token-endpoint response. now is the issue time in unix seconds (defaults to the system clock) and is used to compute :expires_at. Returns {:error, :invalid_token} if no access_token present.

Types

t()

@type t() :: %DomainConnect.Token{
  access_token: String.t(),
  expires_at: integer() | nil,
  expires_in: integer() | nil,
  raw: map(),
  refresh_token: String.t() | nil,
  scope: String.t() | nil,
  token_type: String.t() | nil
}

Functions

expired?(token, now \\ System.os_time(:second))

@spec expired?(t(), integer()) :: boolean()

Whether the token is expired at now (unix seconds). A token with no expiry is treated as not expired.

from_response(response, now \\ System.os_time(:second))

@spec from_response(map(), integer()) :: {:ok, t()} | {:error, :invalid_token}

Builds a Token from a decoded token-endpoint response. now is the issue time in unix seconds (defaults to the system clock) and is used to compute :expires_at. Returns {:error, :invalid_token} if no access_token present.