# `AshAi.Mcp.OAuth.Token`
[🔗](https://github.com/ash-project/ash_ai/blob/v1.5.6/lib/ash_ai/mcp/oauth/token.ex#L5)

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.

# `t`

```elixir
@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()
}
```

# `fresh?`

```elixir
@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`

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

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

# `to_map`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
