An OAuth 2 token set returned by Dropbox's /oauth2/token endpoint.
access_token— the short-lived token used to authenticate API callsrefresh_token— the long-lived token used to mint new access tokens. Only returned by the code exchange; refresh responses leave itnil, since Dropbox does not rotate refresh tokens (keep the original one)expires_at— absolute expiry, computed from Dropbox'sexpires_inscope— space-separated scopes granted to the token, when presentaccount_id/uid— the Dropbox account the token belongs to (code exchange only)
Summary
Functions
Returns true when the token is usable for at least margin more seconds.
Builds a token from a decoded /oauth2/token response body.
Types
Functions
@spec fresh?(t(), non_neg_integer()) :: boolean()
Returns true when the token is usable for at least margin more seconds.
A token without an expires_at is never considered fresh — its expiry is
unknown, so it is safer to refresh it.
iex> token = %Magpie.Auth.Token{access_token: "sl.ABC", expires_at: DateTime.add(DateTime.utc_now(), 3600)}
iex> Magpie.Auth.Token.fresh?(token, 300)
true
iex> Magpie.Auth.Token.fresh?(%Magpie.Auth.Token{}, 300)
false
Builds a token from a decoded /oauth2/token response body.
expires_in (seconds from now) is turned into an absolute expires_at.
iex> body = %{"access_token" => "sl.ABC", "expires_in" => 14_400, "token_type" => "bearer"}
iex> token = Magpie.Auth.Token.from_response(body)
iex> token.access_token
"sl.ABC"
iex> DateTime.diff(token.expires_at, DateTime.utc_now()) > 14_000
true