Skip to main content

get_credentials

Function get_credentials 

Source
pub async fn get_credentials(
    explicit_token: Option<&str>,
) -> Result<String, AuthError>
Expand description

Retrieves an OAuth2 access token for Google Cloud Artifact Registry.

Credential resolution order:

  1. explicit_token (used unchanged if valid).
  2. Google Application Default Credentials (ADC) via service account file or user ADC.
  3. Fallback to gcloud auth print-access-token CLI command.

§Arguments

  • explicit_token - Optional override token passed by the user.

§Errors

Returns AuthError::CredentialsUnavailable if both credential providers fail, or AuthError::Config if an explicit token is invalid.

§Example

use node_auth::auth::get_credentials;

let token = get_credentials(Some("custom-token")).await?;
assert_eq!(token, "custom-token");