Skip to main content

Crate tongbal_oauth

Crate tongbal_oauth 

Source
Expand description

OAuth 2.0 authorization client for the Chzzk API.

Handles the authorization code flow.

§Quick Start

use std::str::FromStr;
use tongbal_oauth::{ClientId, ClientSecret, RedirectUrl, TongbalOauth};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let oauth = TongbalOauth::new(
        ClientId::from("client_id"),
        ClientSecret::from("client_secret"),
        RedirectUrl::from_str("http://localhost:3000/auth/callback")?,
    );

    let auth_url = oauth.auth_url();
    println!("Visit: {}", auth_url);

    Ok(())
}

§Handling OAuth Callbacks

use tongbal_oauth::{AuthCallback, Error, TongbalOauth};

async fn handle_callback(
    oauth: &TongbalOauth,
    callback: AuthCallback,
) -> Result<(), Error> {
    let token = oauth
        .exchange_code(callback.code, callback.state)
        .await?;

    Ok(())
}

§Token Management

§Refresh

let new_token = oauth.refresh_token(refresh_token).await?;

§Revocation

Both AccessToken and RefreshToken can be revoked.

oauth.revoke_token(access_token).await?;
oauth.revoke_token(refresh_token).await?;

§HTTP Client

A suitable HTTP client for authorization is used by default. If customization is needed, see client::setup.

Modules§

client
Global HTTP Client Management for OAuth Request
csrf

Structs§

AccessToken
AuthCallback
AuthUrl
AuthorizationCode
ClientId
ClientSecret
RedirectUrl
RefreshToken
Response
RevocationUrl
Token
TokenUrl
TongbalOauth

Enums§

Error