# `WardrikOAuth.Token`

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

# `t`

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

# `carry_refresh`

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

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

# `decode`

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

Decodes a token from JSON.

# `encode`

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

Encodes the token as JSON.

# `expire`

```elixir
@spec expire(t()) :: t()
```

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

# `fresh?`

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

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

# `from_response`

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

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

Returns whether the token can be refreshed.

---

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