#oauth2 #oauth #gcp #google-cloud #google-api

gcp-sa

Google Cloud Platform Service Account OAuth authentication abstraction

1 unstable release

0.1.2 Mar 28, 2021
0.1.1 Mar 28, 2021
0.1.0 Mar 28, 2021

#625 in Authentication

Download history 670/week @ 2024-11-15 521/week @ 2024-11-22 830/week @ 2024-11-29 858/week @ 2024-12-06 600/week @ 2024-12-13 233/week @ 2024-12-20 42/week @ 2024-12-27 469/week @ 2025-01-03 390/week @ 2025-01-10 550/week @ 2025-01-17 547/week @ 2025-01-24 737/week @ 2025-01-31 619/week @ 2025-02-07 351/week @ 2025-02-14 1028/week @ 2025-02-21 1108/week @ 2025-02-28

3,329 downloads per month

MIT license

15KB
260 lines

Google Cloud Platform Service Account OAuth authentication abstraction for Rust

A service account is a special kind of account used by an application or a virtual machine (VM) instance, not a person. Applications use service accounts to make authorized API calls, authorized as either the service account itself, or as Google Workspace or Cloud Identity users through domain-wide delegation.

API calls can target a Google API or your own Cloud Function or Cloud Run instance endpoint that you have protected with Cloud IAM.

Example

Simple example for acquiring an ID token (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();

Simple example for acquiring an Access Token:

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();

After acquiring a token you need you can use it as a bearer token in HTTP request headers e.g:

let header = format!("Authorization: Bearer {}", token);

Dependencies

~8–22MB
~355K SLoC