3个不稳定版本
使用旧的Rust 2015
0.3.0 | 2018年5月18日 |
---|---|
0.2.1 | 2018年4月6日 |
0.2.0 | 2018年4月6日 |
966 在 身份验证 中排名
每月 下载量 39
13KB
166 行
Rust Google Sign-In
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端点,它处理大部分验证逻辑,但引入了一些延迟。
如果您预计将有大量登录
- 请对 处理证书和Cache-Control身份验证流程 问题添加反应,以便我们知道有多少人需要它。
- 或者,提交一个Pull Request来帮助解决这个问题。
依赖关系
~4.5–7MB
~179K SLoC