#google-api #google #gcp #authentication #google-service #env-var

gauthenticator

用于与 Google 服务进行认证的简单 API,项目主页:https://github.com/isaacadams/bq-rs

2 个版本

0.2.2 2024 年 5 月 27 日
0.2.1 2024 年 5 月 25 日
0.1.6 2024 年 5 月 25 日
0.1.5 2024 年 4 月 23 日
0.1.2 2023 年 11 月 25 日

1669网页开发

每月 50 次下载
用于 bq-rs

MIT/Apache 许可

30KB
569

使用方法

有三种方式可以加载 Google 服务的认证凭据。

// 1. load credentials from an environment variable
let authentication = gauthenticator::from_environment_variable("SOME_ENV_VAR");
// 2. load credentials from a file path
let authentication = gauthenticator::from_file("/path/to/credentials.json");
// 3. load credentials from your machine's environment using well known locations
let authentication = gauthenticator::from_env().authentication();

let Some(authentication) = authentication else {
    panic!("failed to find credentials");
};

// log out the authentication details
log::debug!("{}", authentication.message());

// load project id from user input or from the service account file
let project_id = authentication.project_id().expect("project id is required");

// create the bearer token
let token = authentication.token(None)?;

依赖

~11–20MB
~385K SLoC