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

§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.13.0" }. 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§

Modules§

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

Macros§

Structs§

Enums§

Statics§

  • Authorization URL (https://id.twitch.tv/oauth2/authorize) for id.twitch.tv
  • Revokation URL (https://id.twitch.tv/oauth2/revoke) for id.twitch.tv
  • Token URL (https://id.twitch.tv/oauth2/token) for id.twitch.tv
  • Validation URL (https://id.twitch.tv/oauth2/validate) for id.twitch.tv

Traits§