#oauth2 #oauth #gcp #google-api

gcp-sa

Google Cloud Platform Service Account OAuth认证抽象

1个不稳定版本

0.1.2 2021年3月28日
0.1.1 2021年3月28日
0.1.0 2021年3月28日

认证中排名第963

Download history 27/week @ 2024-03-28 26/week @ 2024-04-04 5/week @ 2024-05-02 593/week @ 2024-05-09 297/week @ 2024-05-16 633/week @ 2024-05-23 742/week @ 2024-05-30 464/week @ 2024-06-06 410/week @ 2024-06-13 362/week @ 2024-06-20 164/week @ 2024-06-27

每月下载量1,690

MIT许可证

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