Crates.io | oauth2_utils |
lib.rs | oauth2_utils |
version | 2.0.0 |
source | src |
created_at | 2023-12-18 00:38:46.220369 |
updated_at | 2024-04-09 13:46:06.305124 |
description | crate that provides utility functions for working with OAuth2 |
homepage | |
repository | https://github.com/ashgw/oauth2_utils |
max_upload_size | |
id | 1072853 |
size | 52,689 |
This crate provides utility functions for working with OAuth2:
cargo add oauth2_utils
To generate a PKCE pair with the corresponding method (SHA256 by default):
use oauth2_utils::pkce::PKCE;
let pkce = PKCE::new();
println!("PKCE Code Challenge: {}", pkce.code_challenge);
println!("PKCE Code Verifier: {}", pkce.code_verifier);
println!("PKCE Code method: {}", pkce.method);
To generate a code verifier with a custom length:
use oauth2_utils::errors::CodeVerifierError;
use oauth2_utils::pkce::gen::{gen_code_challenge, gen_code_verifier};
pub fn main() -> Result<(), CodeVerifierError> {
let code_verifier = gen_code_verifier(Some(128))?;
eprintln!("Code Verifier: {}", code_verifier);
let code_challenge = gen_code_challenge(&code_verifier);
eprintln!("Code Challenge: {}", code_challenge);
Ok(())
}
To generate a URL-safe token for Nonce, State, etc..
use oauth2_utils::urlsafe::urlsafe_token;
println!("URL-safe Token: {}", urlsafe_token(32))
For base64 encoding/decoding operations:
use oauth2_utils::errors::B64Error;
use oauth2_utils::urlsafe::b64::{urlsafe_b64decode, urlsafe_b64encode};
pub fn main() -> Result<(), B64Error> {
let val = String::from("some value");
let encoded = urlsafe_b64encode(val);
println!("{}", encoded);
let decoded = urlsafe_b64decode(encoded)?;
println!("{}", decoded);
Ok(())
}