3个不稳定版本

使用旧的Rust 2015

0.3.0 2018年5月18日
0.2.1 2018年4月6日
0.2.0 2018年4月6日

966身份验证 中排名

每月 下载量 39

MIT/Apache

13KB
166

Rust Google Sign-In

google-signin on crates.io google-signin on docs.rs

Rust对Google Sign-in的API绑定。
参见 使用后端服务器进行身份验证.

用法

在您的 Cargo.toml 中加入以下内容

[dependencies]
google-signin = "0.3.0"

并在您的crate根目录中加入以下内容

extern crate google_signin;

然后您就可以验证Google JSON Web令牌

use google_signin;
let mut client = google_signin::Client::new();
client.audiences.push(YOUR_CLIENT_ID); // required
client.hosted_domains.push(YOUR_HOSTED_DOMAIN); // optional

// Let the crate handle everything for you
let id_info = client.verify(&data.token).expect("Expected token to be valid");
println!("Success! Signed-in as {}", id_info.sub);

// Inspect the ID before verifying it
let id_info = client.get_slow_unverified(&data.token).expect("Expected token to exist");
let ok = id_info.verify(&client).is_ok();
println!("Ok: {}, Info: {:?}", ok, id_info);

其他注意事项

当前 verify 函数使用 tokeninfo端点,它处理大部分验证逻辑,但引入了一些延迟。

如果您预计将有大量登录

依赖关系

~4.5–7MB
~179K SLoC