https://github.com/timelessnesses/tlns-google-oauth2
An enshitificated Google OAuth2 Server Side support for Rust with built in Scopes enum
https://github.com/timelessnesses/tlns-google-oauth2
actix google login macro oauth2 proc provider rust scopes server web
Last synced: 5 months ago
JSON representation
An enshitificated Google OAuth2 Server Side support for Rust with built in Scopes enum
- Host: GitHub
- URL: https://github.com/timelessnesses/tlns-google-oauth2
- Owner: timelessnesses
- License: mit
- Created: 2024-06-29T12:27:22.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-13T06:02:31.000Z (almost 2 years ago)
- Last Synced: 2025-03-09T04:19:02.854Z (about 1 year ago)
- Topics: actix, google, login, macro, oauth2, proc, provider, rust, scopes, server, web
- Language: Rust
- Homepage: https://crates.io/crates/tlns_google_oauth2
- Size: 280 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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](https://developers.google.com/identity/protocols/oauth2/scopes) and start copying from the first header to the final row of the table at the bottom of the document.


Then pasting all of that to the `info.txt` and build the library, it will give you all possible scopes!
## Usage ([`crate::grouped_scopes`])
```rust,should_panic
fn main() -> Result<(), Box> {
use tlns_google_oauth2::GoogleOAuth2Client as Client;
use tlns_google_oauth2::grouped_scopes;
use pollster::FutureExt as _;
let client = Client::new("CLIENT_ID", "CLIENT_SECRET", "http://localhost:8080/callback")?;
let auth = client.build_authorize_url(None, &[&grouped_scopes::GoogleOAuth2APIv2::AuthUserinfoProfile]);
let url = auth.redirect_url;
let csrf_token = auth.csrf_token;
let scopes = auth.scopes;
// ... Callback codes here (You can't save states in oauth2 crate for some reasons :( )
let code = "...";
let token = client.get_token(code, None).block_on()?;
// Do request stuff
Ok(())
}
```
## Usage ([`crate::scopes::Scopes`])
```rust,should_panic
fn main() -> Result<(), Box> {
use tlns_google_oauth2::GoogleOAuth2Client as Client;
use tlns_google_oauth2::scopes;
use pollster::FutureExt as _;
let client = Client::new("CLIENT_ID", "CLIENT_SECRET", "http://localhost:8080/callback")?;
let auth = client.build_authorize_url(None, &[&scopes::Scopes::AuthUserinfoProfile]);
let url = auth.redirect_url;
let csrf_token = auth.csrf_token;
let scopes = auth.scopes;
// ... Callback codes here (You can't save states in oauth2 crate for some reasons :( )
let code = "...";
let token = client.get_token(code, None).block_on()?;
Ok(())
// Do request stuff
}
```
Yes, you can mix and match the slice with anything that implements [`ToGoogleScope`] trait.
## Credits
Thanks [`heapunderfl0w`](https://github.com/heapunderfl0w) for the proc macro idea instead of shitty Jinja2 implementation!