Crate twitch_oauth2

Source
Expand description

githubcrates-iodocs-rs


OAuth2 for Twitch endpoints
use twitch_oauth2::{tokens::errors::ValidationError, AccessToken, TwitchToken, UserToken};
// Make sure you enable the feature "reqwest" for twitch_oauth2 if you want to use reqwest
let client = reqwest::Client::builder()
    .redirect(reqwest::redirect::Policy::none())
    .build()?;
let token = AccessToken::new("sometokenherewhichisvalidornot".to_string());
let token = UserToken::from_token(&client, token).await?;
println!("token: {:?}", token.token()); // prints `[redacted access token]`

§About

§Scopes

The library contains all known twitch oauth2 scopes in Scope.

§User Access Tokens

For most basic use cases with user authorization, UserToken::from_token will be your main way to create user tokens in this library.

Things like UserTokenBuilder can be used to create a token from scratch, via the OAuth authorization code flow You can also use the newer OAuth device code flow with DeviceUserTokenBuilder.

§App access token

Similar to UserToken, a token with authorization as the twitch application can be created with AppAccessToken::get_app_access_token.

§HTTP Requests

To enable client features with a supported http library, enable the http library feature in twitch_oauth2, like twitch_oauth2 = { features = ["reqwest"], version = "0.15.1" }. If you’re using twitch_api, you can use its HelixClient instead of the underlying http client.

This library can be used without any specific http client library (like if you don’t want to use await), using methods like AppAccessToken::from_response and AppAccessToken::get_app_access_token_request or UserTokenBuilder::get_user_token_request and UserToken::from_response

Re-exports§

pub use types::AccessToken;
pub use types::ClientId;
pub use types::ClientSecret;
pub use types::CsrfToken;
pub use types::RefreshToken;
pub use url;

Modules§

clientclient
Provides different http clients
id
Representation of oauth2 flow in id.twitch.tv
scopes
Module for all possible scopes in twitch.
tokens
Twitch token types
types
Types used in OAUTH2 flow.

Macros§

validator
A validator is a way to check if a slice of scopes matches a predicate.

Structs§

AppAccessToken
An App Access Token from the OAuth client credentials flow
DeviceUserTokenBuilder
Builder for OAuth device code flow
ImplicitUserTokenBuilder
Builder for OAuth implicit code flow
UserToken
An User Token from the OAuth implicit code flow or OAuth authorization code flow
UserTokenBuilder
Builder for OAuth authorization code flow
ValidatedToken
Token validation returned from https://id.twitch.tv/oauth2/validate

Enums§

RequestParseError
Errors from parsing responses
Scope
Scopes for twitch.
Validator
A validator is a way to check if an array of scopes matches a predicate.

Statics§

AUTH_URL
Authorization URL (https://id.twitch.tv/oauth2/authorize) for id.twitch.tv
DEVICE_URL
Device URL (https://id.twitch.tv/oauth2/device) for id.twitch.tv
REVOKE_URL
Revokation URL (https://id.twitch.tv/oauth2/revoke) for id.twitch.tv
TOKEN_URL
Token URL (https://id.twitch.tv/oauth2/token) for id.twitch.tv
VALIDATE_URL
Validation URL (https://id.twitch.tv/oauth2/validate) for id.twitch.tv

Traits§

TwitchToken
Trait for twitch tokens to get fields and generalize over AppAccessToken and UserToken