#[non_exhaustive]pub struct TokenResponseFields {
pub access_token: String,
pub refresh_token: Option<String>,
pub expires_in: Option<u64>,
pub token_type: Option<String>,
pub id_token: Option<String>,
pub scope: Option<String>,
}Expand description
The standard fields extracted from a token endpoint response.
Consumed internally by loopauth to build a crate::TokenSet.
For the standard flat OAuth 2.0 response format, this struct is
deserialized directly. For non-standard providers, define a custom type
that implements Into<TokenResponseFields> and pass it to
CliTokenClientBuilder::token_response_type.
§Example: Custom provider response
use loopauth::TokenResponseFields;
use serde::Deserialize;
#[derive(Deserialize)]
struct SlackV2TokenResponse {
authed_user: SlackAuthedUser,
}
#[derive(Deserialize)]
struct SlackAuthedUser {
access_token: String,
refresh_token: Option<String>,
expires_in: Option<u64>,
}
impl From<SlackV2TokenResponse> for TokenResponseFields {
fn from(resp: SlackV2TokenResponse) -> Self {
TokenResponseFields::new(resp.authed_user.access_token)
.with_refresh_token(resp.authed_user.refresh_token)
.with_expires_in(resp.authed_user.expires_in)
.with_token_type(Some("Bearer".to_string()))
}
}Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.access_token: StringThe access token issued by the authorization server.
refresh_token: Option<String>The refresh token, if the server issued one.
expires_in: Option<u64>The lifetime in seconds of the access token.
token_type: Option<String>The token type (e.g., "Bearer").
id_token: Option<String>The ID token JWT, if OpenID Connect was requested.
scope: Option<String>The scope granted by the server (space-separated).
Implementations§
Source§impl TokenResponseFields
impl TokenResponseFields
Sourcepub const fn new(access_token: String) -> Self
pub const fn new(access_token: String) -> Self
Create a new TokenResponseFields with the required access token.
All optional fields default to None. Use the with_* methods to set them.
Sourcepub fn with_refresh_token(self, refresh_token: Option<String>) -> Self
pub fn with_refresh_token(self, refresh_token: Option<String>) -> Self
Set the refresh token.
Sourcepub const fn with_expires_in(self, expires_in: Option<u64>) -> Self
pub const fn with_expires_in(self, expires_in: Option<u64>) -> Self
Set the token lifetime in seconds.
Sourcepub fn with_token_type(self, token_type: Option<String>) -> Self
pub fn with_token_type(self, token_type: Option<String>) -> Self
Set the token type.
Sourcepub fn with_id_token(self, id_token: Option<String>) -> Self
pub fn with_id_token(self, id_token: Option<String>) -> Self
Set the ID token JWT.
Sourcepub fn with_scope(self, scope: Option<String>) -> Self
pub fn with_scope(self, scope: Option<String>) -> Self
Set the granted scope.
Trait Implementations§
Source§impl Clone for TokenResponseFields
impl Clone for TokenResponseFields
Source§fn clone(&self) -> TokenResponseFields
fn clone(&self) -> TokenResponseFields
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more