1个不稳定版本
0.1.2 | 2021年3月28日 |
---|---|
0.1.1 |
|
0.1.0 |
|
在认证中排名第963
每月下载量1,690次
15KB
260 行
Rust的Google Cloud Platform Service Account OAuth认证抽象
服务帐户是一种特殊类型的帐户,用于应用程序或虚拟机(VM)实例,而不是个人。应用程序使用服务帐户来执行授权的API调用,这些调用可以以服务帐户本身或通过域内代理作为Google Workspace或Cloud Identity用户的名义进行授权。
API调用可以针对Google API或您自己的受Cloud IAM保护的保护的Cloud Function或Cloud Run实例端点。
示例
获取ID令牌(JWT)的简单示例
let authenticator = GoogleServiceAccountAuthenticator::new_from_service_account_key_file(std::path::Path("key.json".to_string())).unwrap();
let token = authenticator.request_id_token("https://my-google-app.endpoint.tld/something").await.unwrap();
获取访问令牌的简单示例
let authenticator = GoogleServiceAccountAuthenticator::new_from_service_account_key_file(std::path::Path("key.json".to_string())).unwrap();
let token = authenticator.request_access_token().await.unwrap();
获取所需的令牌后,您可以用它作为HTTP请求头中的承载令牌,例如
let header = format!("Authorization: Bearer {}", token);
依赖项
~7–21MB
~341K SLoC