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§

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,
        )
    }

Assemble token and validate it. Retrieves client_id and scopes.

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)
    }

Generate app access token via OAuth client credentials flow

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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Get the type of token.
Client ID associated with the token. Twitch requires this in all helix API calls
Get the AccessToken for authenticating Read more
Get the username associated to this token
Get the user id associated to this token
Refresh this token, changing the token to a newer one
Get current lifetime of token.
Retrieve scopes attached to the token
Returns whether or not the token is expired. Read more
Validate this token. Should be checked on regularly, according to https://dev.twitch.tv/docs/authentication#validating-requests Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more