AshAi.Mcp.OAuth.Token (ash_ai v1.5.6)

Copy Markdown View Source

The tokens one owner holds for one MCP server.

Besides the token response itself, a token records what refreshing it needs: the authorization server's issuer and token_endpoint, the client_id it was issued to, and the resource it is bound to.

scope is the granted scope, space-separated. When the token response omits it, it is the scope that was requested.

Summary

Functions

Whether the access token is still usable skew seconds from now.

Builds a token from a map produced by to_map/1.

Converts the token to a JSON-safe map with string keys.

Types

t()

@type t() :: %AshAi.Mcp.OAuth.Token{
  access_token: String.t(),
  client_id: String.t(),
  expires_at: DateTime.t() | nil,
  issuer: String.t(),
  obtained_at: DateTime.t() | nil,
  refresh_token: String.t() | nil,
  resource: String.t(),
  scope: String.t() | nil,
  server_url: String.t(),
  token_endpoint: String.t(),
  token_type: String.t()
}

Functions

fresh?(token, skew)

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

Whether the access token is still usable skew seconds from now.

A token without an expiry is assumed usable until the server rejects it.

from_map(map)

@spec from_map(map()) :: t()

Builds a token from a map produced by to_map/1.

to_map(token)

@spec to_map(t()) :: map()

Converts the token to a JSON-safe map with string keys.