# `Ltix.OAuth.AccessToken`
[🔗](https://github.com/DecoyLex/ltix/blob/main/lib/ltix/oauth/access_token.ex#L1)

OAuth 2.0 access token response.

A cacheable struct holding the parsed token data from a platform's token
endpoint. Host apps can store this and reuse it across contexts via
`Ltix.OAuth.Client.from_access_token/2`.

## Examples

    iex> {:ok, token} = Ltix.OAuth.AccessToken.from_response(
    ...>   %{
    ...>     "access_token" => "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9",
    ...>     "token_type" => "Bearer",
    ...>     "expires_in" => 3600,
    ...>     "scope" => "https://purl.imsglobal.org/spec/lti-nrps/scope/contextmembership.readonly"
    ...>   },
    ...>   now: ~U[2025-01-01 00:00:00Z]
    ...> )
    iex> token.access_token
    "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9"
    iex> token.token_type
    "bearer"
    iex> token.granted_scopes
    ["https://purl.imsglobal.org/spec/lti-nrps/scope/contextmembership.readonly"]
    iex> token.expires_at
    ~U[2025-01-01 01:00:00Z]

# `t`

```elixir
@type t() :: %Ltix.OAuth.AccessToken{
  access_token: String.t(),
  expires_at: DateTime.t(),
  granted_scopes: [String.t()],
  token_type: String.t()
}
```

# `from_response`

```elixir
@spec from_response(
  map(),
  keyword()
) :: {:ok, t()} | {:error, Exception.t()}
```

Parse an access token from a token endpoint response body.

## Options

  * `:requested_scopes` - list of scope strings that were requested, used
    as fallback when the response omits `"scope"`.
  * `:now` - override current time (default: `DateTime.utc_now/0`).

---

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