pub struct TokenResponse {
pub access_token: String,
pub token_type: String,
pub expires_in: Option<u64>,
pub refresh_token: Option<String>,
pub scope: Option<Scopes>,
pub id_token: Option<String>,
pub extra: Json,
}Expand description
What a token endpoint returns on success.
Debug redacts the secrets. This type is what a developer prints while
debugging a grant, and an access token in a log file is a live credential.
Fields§
§access_token: String§token_type: String§expires_in: Option<u64>Seconds from issue, not an absolute time — that is what the wire carries.
refresh_token: Option<String>§scope: Option<Scopes>Present when the provider granted something other than what was asked.
id_token: Option<String>OpenID Connect’s identity token, when openid was requested.
extra: JsonEverything else the provider sent, kept so provider-specific fields are not lost.
Implementations§
Source§impl TokenResponse
impl TokenResponse
pub fn bearer(access_token: impl Into<String>) -> TokenResponse
pub fn expiring_in(self, seconds: u64) -> TokenResponse
pub fn with_refresh_token(self, token: impl Into<String>) -> TokenResponse
pub fn with_scopes(self, scopes: Scopes) -> TokenResponse
Sourcepub fn from_json(body: &Json) -> Result<TokenResponse, OAuthError>
pub fn from_json(body: &Json) -> Result<TokenResponse, OAuthError>
Parse a token endpoint’s JSON response.
An error field wins over everything else, whatever the HTTP status —
enough providers return 200 with an error body that trusting the status
alone means silently treating a failure as a success.
pub fn to_json(&self) -> Json
The value for an Authorization header.
Sourcepub fn expires_within(&self, elapsed_seconds: u64, slack: u64) -> bool
pub fn expires_within(&self, elapsed_seconds: u64, slack: u64) -> bool
Whether the token is within slack seconds of expiring.
Refreshing early is deliberate: a token that expires while a request is in flight fails, and the caller has no way to tell that apart from a revoked token.