4 releases

0.0.4 Mar 2, 2024
0.0.3 Feb 29, 2024
0.0.2 Feb 29, 2024
0.0.1 Feb 29, 2024

#333 in Authentication

21 downloads per month

MIT/Apache

14KB
287 lines

twitch oauth token


lib.rs:

 use tokio::net::TcpListener;
 use twitch_oauth_token::{pkce::Pkce, Token, TwitchOauth};

 #[tokio::main]
 async fn main() -> Result<(), twitch_oauth::Error> {
     let (pkce_challenge, code_verifier) = Pkce::new_sha256().unwrap();
     // duration 10 sec
     let oauth = TwitchOauth::new("client_id", "client_secret", pkce_challenge, 10);

     let auth_url = oauth.auth_request_url("chat:read");

     // only can bind 3000
     let listener = TcpListener::bind("127.0.0.1:3000")
         .await
         .expect("Failed already bind 3000");

     println!("{}", auth_url);

     let (code, state) = oauth.oauth_server_sync(listener).await?;

     code_verifier(state).unwrap();

     let token = oauth.get_token_json(code).await?;

     Ok(())
 }

Dependencies

~12–27MB
~489K SLoC