tlns-google-oauth2

Crates.iotlns-google-oauth2
lib.rstlns-google-oauth2
version0.4.1
sourcesrc
created_at2024-06-29 17:14:45.596215
updated_at2024-07-13 06:02:38.411866
descriptionAn enshitificated Google OAuth2 Server Side support for Rust with built in Scopes enum
homepage
repositoryhttps://github.com/timelessnesses/tlns-google-oauth2
max_upload_size
id1287507
size42,828
Rukchad Wongprayoon (timelessnesses)

documentation

https://docs.rs/tlns-google-oauth2

README

tlns-google-oauth2

A server-side Google OAuth2 authentication with built in scopes for extra type safety.

Generating scopes enums (for proc macro library part only)

Go to Google's OAuth2 Scopes Listing and start copying from the first header to the final row of the table at the bottom of the document. A picture showing the first blue header A picture showing the last row of the table Then pasting all of that to the info.txt and build the library, it will give you all possible scopes!

Usage ([crate::grouped_scopes])

use tlns_google_oauth2::GoogleOAuth2Client as Client;
use tlns_google_oauth2::scopes;
let client = Client::new("CLIENT_ID".to_string(), "CLIENT_SECRET".to_string(), "http://localhost:8080/callback".to_string()).expect("Failed to build client");
let auth = client.authorize_url(None, vec![&scopes::GoogleOAuth2APIv2::AuthUserinfoProfile]).unwrap();
let url = auth.0;
let csrf_token = auth.1;
let scopes = auth.2;

// ... Callback codes here (You can't save states in oauth2 crate for some reasons :( )

let code = "...";
let token = client.get_token(code.to_string()).await.unwrap();
// Do request stuff

Usage ([crate::scopes::Scopes])

use tlns_google_oauth2::GoogleOAuth2Client as Client;
use tlns_google_oauth2::scopes;
let client = Client::new("CLIENT_ID".to_string(), "CLIENT_SECRET".to_string(), "http://localhost:8080/callback".to_string()).expect("Failed to build client");
let auth = client.authorize_url(None, vec![&scopes::Scopes::AuthUserinfoProfile]).unwrap();
let url = auth.0;
let csrf_token = auth.1;
let scopes = auth.2;

// ... Callback codes here (You can't save states in oauth2 crate for some reasons :( )

let code = "...";
let token = client.get_token(code.to_string()).await.unwrap();
// Do request stuff

Credits

Thanks heapunderfl0w for the proc macro idea instead of shitty Jinja2 implementation!

Commit count: 39

cargo fmt