#gcp #google


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

28 releases

0.9.0 Jun 30, 2023
0.8.0 Apr 3, 2023
0.7.6 Mar 27, 2023
0.7.5 Dec 21, 2022
0.1.4 Jul 2, 2020

#19 in Authentication

Download history 6959/week @ 2023-06-06 7364/week @ 2023-06-13 8321/week @ 2023-06-20 8273/week @ 2023-06-27 9251/week @ 2023-07-04 10467/week @ 2023-07-11 12562/week @ 2023-07-18 12743/week @ 2023-07-25 10465/week @ 2023-08-01 12128/week @ 2023-08-08 12764/week @ 2023-08-15 12903/week @ 2023-08-22 10277/week @ 2023-08-29 9873/week @ 2023-09-05 8583/week @ 2023-09-12 10402/week @ 2023-09-19

41,634 downloads per month
Used in 10 crates (8 directly)

MIT license

769 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 get instantiate an AuthenticationManager. It will find the appropriate authentication method and use it to retrieve tokens.

use gcp_auth::AuthenticationManager;

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


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

Licensed under MIT license.


~574K SLoC