#service-account #auth-token #gcp #google-service #google #env-var

gcp_auth

Google cloud platform (GCP) authentication using default and custom service accounts

35 releases

0.12.3 Oct 14, 2024
0.12.2 May 29, 2024
0.11.1 Apr 9, 2024
0.11.0 Mar 14, 2024
0.1.4 Jul 2, 2020

#10 in Authentication

Download history 22661/week @ 2024-07-21 27538/week @ 2024-07-28 30452/week @ 2024-08-04 42059/week @ 2024-08-11 42932/week @ 2024-08-18 52121/week @ 2024-08-25 40672/week @ 2024-09-01 47048/week @ 2024-09-08 42990/week @ 2024-09-15 48293/week @ 2024-09-22 65273/week @ 2024-09-29 33887/week @ 2024-10-06 56493/week @ 2024-10-13 47960/week @ 2024-10-20 56327/week @ 2024-10-27 41639/week @ 2024-11-03

203,205 downloads per month
Used in 15 crates (12 directly)

MIT license

44KB
791 lines

GCP Auth

Crates.io Documentation MIT licensed

GCP auth provides authentication using service accounts Google Cloud Platform (GCP)

GCP auth is a simple, minimal authentication library for Google Cloud Platform (GCP) providing authentication using service accounts. Once authenticated, the service account can be used to acquire bearer tokens for use in authenticating against GCP services.

The library supports the following methods of retrieving tokens in the listed priority order:

  1. Reading custom service account credentials from the path pointed to by the GOOGLE_APPLICATION_CREDENTIALS environment variable. Alternatively, custom service account credentials can be read from a JSON file or string.
  2. Look for credentials in .config/gcloud/application_default_credentials.json; if found, use these credentials to request refresh tokens. This file can be created by invoking gcloud auth application-default login.
  3. Use the default service account by retrieving a token from the metadata server.
  4. Retrieving a token from the gcloud CLI tool, if it is available on the PATH.

For more detailed information and examples, see the docs.

This crate does not currently support Windows.

Simple usage

The default way to use this library is to select the appropriate token provider using provider(). It will find the appropriate authentication method and use it to retrieve tokens.

let provider = gcp_auth::provider().await?;
let scopes = &["https://www.googleapis.com/auth/cloud-platform"];
let token = provider.token(scopes).await?;

License

Parts of the implementation have been sourced from yup-oauth2.

Licensed under MIT license.

Dependencies

~18–29MB
~520K SLoC