Struct twitch_oauth2::AppAccessToken
source · pub struct AppAccessToken {
pub access_token: AccessToken,
pub refresh_token: Option<RefreshToken>,
/* private fields */
}
Expand description
An App Access Token from the OAuth client credentials flow
Used for server-to-server requests. Use UserToken
for requests that need to be in the context of an authenticated user.
In some contexts (i.e EventSub) an App Access Token can be used in the context of users that have authenticated the specific Client ID
Fields§
§access_token: AccessToken
The access token used to authenticate requests with
refresh_token: Option<RefreshToken>
The refresh token used to extend the life of this user token
Implementations§
source§impl AppAccessToken
impl AppAccessToken
sourcepub fn from_existing_unchecked(
access_token: AccessToken,
refresh_token: impl Into<Option<RefreshToken>>,
client_id: impl Into<ClientId>,
client_secret: impl Into<ClientSecret>,
scopes: Option<Vec<Scope>>,
expires_in: Option<Duration>
) -> AppAccessToken
pub fn from_existing_unchecked(
access_token: AccessToken,
refresh_token: impl Into<Option<RefreshToken>>,
client_id: impl Into<ClientId>,
client_secret: impl Into<ClientSecret>,
scopes: Option<Vec<Scope>>,
expires_in: Option<Duration>
) -> AppAccessToken
Assemble token without checks.
If expires_in
is None
, we’ll assume token.is_elapsed() == true
Examples found in repository?
src/tokens/app_access_token.rs (lines 128-135)
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
pub async fn from_existing<'a, RE, C>(
http_client: &'a C,
access_token: AccessToken,
refresh_token: impl Into<Option<RefreshToken>>,
client_secret: ClientSecret,
) -> Result<AppAccessToken, ValidationError<<C as Client<'a>>::Error>>
where
C: Client<'a>,
{
let token = access_token;
let validated = token.validate_token(http_client).await?;
Ok(Self::from_existing_unchecked(
token,
refresh_token.into(),
validated.client_id,
client_secret,
validated.scopes,
validated.expires_in,
))
}
/// Assemble token from twitch responses.
pub fn from_response(
response: crate::id::TwitchTokenResponse,
client_id: impl Into<ClientId>,
client_secret: impl Into<ClientSecret>,
) -> AppAccessToken {
let expires_in = response.expires_in();
AppAccessToken::from_existing_unchecked(
response.access_token,
response.refresh_token,
client_id.into(),
client_secret,
response.scopes,
expires_in,
)
}
sourcepub async fn from_existing<'a, RE, C>(
http_client: &'a C,
access_token: AccessToken,
refresh_token: impl Into<Option<RefreshToken>>,
client_secret: ClientSecret
) -> Result<AppAccessToken, ValidationError<<C as Client<'a>>::Error>>where
C: Client<'a>,
pub async fn from_existing<'a, RE, C>(
http_client: &'a C,
access_token: AccessToken,
refresh_token: impl Into<Option<RefreshToken>>,
client_secret: ClientSecret
) -> Result<AppAccessToken, ValidationError<<C as Client<'a>>::Error>>where
C: Client<'a>,
sourcepub fn from_response(
response: TwitchTokenResponse,
client_id: impl Into<ClientId>,
client_secret: impl Into<ClientSecret>
) -> AppAccessToken
pub fn from_response(
response: TwitchTokenResponse,
client_id: impl Into<ClientId>,
client_secret: impl Into<ClientSecret>
) -> AppAccessToken
Assemble token from twitch responses.
Examples found in repository?
src/tokens/app_access_token.rs (line 174)
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
pub async fn get_app_access_token<'a, C>(
http_client: &'a C,
client_id: ClientId,
client_secret: ClientSecret,
scopes: Vec<Scope>,
) -> Result<AppAccessToken, AppAccessTokenError<<C as Client<'a>>::Error>>
where
C: Client<'a>,
{
let req = Self::get_app_access_token_request(&client_id, &client_secret, scopes);
let resp = http_client
.req(req)
.await
.map_err(AppAccessTokenError::Request)?;
let response = crate::id::TwitchTokenResponse::from_response(&resp)?;
let app_access = AppAccessToken::from_response(response, client_id, client_secret);
Ok(app_access)
}
sourcepub async fn get_app_access_token<'a, C>(
http_client: &'a C,
client_id: ClientId,
client_secret: ClientSecret,
scopes: Vec<Scope>
) -> Result<AppAccessToken, AppAccessTokenError<<C as Client<'a>>::Error>>where
C: Client<'a>,
pub async fn get_app_access_token<'a, C>(
http_client: &'a C,
client_id: ClientId,
client_secret: ClientSecret,
scopes: Vec<Scope>
) -> Result<AppAccessToken, AppAccessTokenError<<C as Client<'a>>::Error>>where
C: Client<'a>,
Generate app access token via OAuth client credentials flow
sourcepub fn get_app_access_token_request(
client_id: &ClientIdRef,
client_secret: &ClientSecretRef,
scopes: Vec<Scope>
) -> Request<Vec<u8>>
pub fn get_app_access_token_request(
client_id: &ClientIdRef,
client_secret: &ClientSecretRef,
scopes: Vec<Scope>
) -> Request<Vec<u8>>
Get the request for getting a app access token.
Parse with TwitchTokenResponse::from_response and AppAccessToken::from_response
Examples found in repository?
src/tokens/app_access_token.rs (line 166)
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
pub async fn get_app_access_token<'a, C>(
http_client: &'a C,
client_id: ClientId,
client_secret: ClientSecret,
scopes: Vec<Scope>,
) -> Result<AppAccessToken, AppAccessTokenError<<C as Client<'a>>::Error>>
where
C: Client<'a>,
{
let req = Self::get_app_access_token_request(&client_id, &client_secret, scopes);
let resp = http_client
.req(req)
.await
.map_err(AppAccessTokenError::Request)?;
let response = crate::id::TwitchTokenResponse::from_response(&resp)?;
let app_access = AppAccessToken::from_response(response, client_id, client_secret);
Ok(app_access)
}
Trait Implementations§
source§impl Clone for AppAccessToken
impl Clone for AppAccessToken
source§fn clone(&self) -> AppAccessToken
fn clone(&self) -> AppAccessToken
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for AppAccessToken
impl Debug for AppAccessToken
source§impl TwitchToken for AppAccessToken
impl TwitchToken for AppAccessToken
source§fn token_type() -> BearerTokenType
fn token_type() -> BearerTokenType
Get the type of token.
source§fn client_id(&self) -> &ClientId
fn client_id(&self) -> &ClientId
Client ID associated with the token. Twitch requires this in all helix API calls
source§fn token(&self) -> &AccessToken
fn token(&self) -> &AccessToken
Get the AccessToken for authenticating Read more
source§fn login(&self) -> Option<&UserNameRef>
fn login(&self) -> Option<&UserNameRef>
Get the username associated to this token
source§fn refresh_token<'a, 'life0, 'async_trait, C>(
&'life0 mut self,
http_client: &'a C
) -> Pin<Box<dyn Future<Output = Result<(), RefreshTokenError<<C as Client<'a>>::Error>>> + Send + 'async_trait>>where
C: Client<'a> + 'async_trait,
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
fn refresh_token<'a, 'life0, 'async_trait, C>(
&'life0 mut self,
http_client: &'a C
) -> Pin<Box<dyn Future<Output = Result<(), RefreshTokenError<<C as Client<'a>>::Error>>> + Send + 'async_trait>>where
C: Client<'a> + 'async_trait,
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
Refresh this token, changing the token to a newer one
source§fn expires_in(&self) -> Duration
fn expires_in(&self) -> Duration
Get current lifetime of token.
source§fn is_elapsed(&self) -> bool
fn is_elapsed(&self) -> bool
Returns whether or not the token is expired. Read more
source§fn validate_token<'a, 'life0, 'async_trait, C>(
&'life0 self,
http_client: &'a C
) -> Pin<Box<dyn Future<Output = Result<ValidatedToken, ValidationError<<C as Client<'a>>::Error>>> + Send + 'async_trait>>where
Self: Sized + Sync + 'async_trait,
C: Client<'a> + 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
fn validate_token<'a, 'life0, 'async_trait, C>(
&'life0 self,
http_client: &'a C
) -> Pin<Box<dyn Future<Output = Result<ValidatedToken, ValidationError<<C as Client<'a>>::Error>>> + Send + 'async_trait>>where
Self: Sized + Sync + 'async_trait,
C: Client<'a> + 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
Validate this token. Should be checked on regularly, according to https://dev.twitch.tv/docs/authentication#validating-requests Read more
source§fn revoke_token<'a, 'async_trait, C>(
self,
http_client: &'a C
) -> Pin<Box<dyn Future<Output = Result<(), RevokeTokenError<<C as Client<'a>>::Error>>> + Send + 'async_trait>>where
Self: Sized + Send + 'async_trait,
C: Client<'a> + 'async_trait,
'a: 'async_trait,
fn revoke_token<'a, 'async_trait, C>(
self,
http_client: &'a C
) -> Pin<Box<dyn Future<Output = Result<(), RevokeTokenError<<C as Client<'a>>::Error>>> + Send + 'async_trait>>where
Self: Sized + Send + 'async_trait,
C: Client<'a> + 'async_trait,
'a: 'async_trait,
Revoke the token. See https://dev.twitch.tv/docs/authentication#revoking-access-tokens