Crate google_oauth
source ·Expand description
Google-Oauth
A server-side google oauth2 verification library for rust.
Installation
This library is hosted on crates.io
[dependencies]
google-oauth = "1"
Usage
The Library provides API to verify id_token
from Google.
Example: Blocking
// With blocking client, we don't need async runtime.
use google_oauth::Client; // This is a blocking client
let client_id = "The client_id generated from google...";
let client = Client::new(client_id); // now we get this.
let data = client.validate_id_token("The id_token you want to validate").unwrap();
// if ok, we get the data...
let sub = data.sub.as_str();
println!("Hello, user (sub = {}) now is online", sub);
Example: Async
// When you use async client, remember to add a async runtime (e.g, `tokio` or `async_std`)
use google_oauth::AsyncClient; // This is a async client
// It works just like the blocking client, excepts the verification step.
#[tokio::main]
async fn main() {
let client_id = "...";
let client = AsyncClient::new(client_id);
/// note: use `await`
let data = client.validate_id_token("The id_token you want to validate").await.unwrap();
// it `unwrap()` is ok, we get the data ...
println!("Hello, user (sub = {}) now is online", sub);
}
Structs
- AsyncClient is an async client to do verification.
- Client is a blocking client to do verification.
GooglePayload
is the user data from google. see https://developers.google.com/identity/openid-connect/openid-connect for more info.