Skip to main content

GoogleAuthHeaders

Struct GoogleAuthHeaders 

Source
pub struct GoogleAuthHeaders { /* private fields */ }
Expand description

The authentication headers of google-cloud-auth credentials, for every request the tonic and reqwest middleware send: authorization with an access token or an ID token, and whatever else the credentials add, such as x-goog-user-project for a quota project.

The credentials mint, cache and refresh the tokens. A GoogleAuthHeaders keeps the headers of the current token, with authorization marked sensitive so that it stays out of logs, and takes new ones only when the credentials report a new token.

from_adc, from_adc_with_scopes, id_token_from_adc and id_token_impersonating build credentials, which spawns their refresh task on the current Tokio runtime.

Implementations§

Source§

impl GoogleAuthHeaders

Source

pub async fn id_token_from_adc(audience: &IdTokenAudience) -> Result<Self>

ID tokens for audience, minted with the identity of the Application Default Credentials:

  • a service account key file, as that service account;
  • the metadata server, as the service account of the instance;
  • impersonated_service_account credentials, such as gcloud auth application-default login --impersonate-service-account writes, as the service account they impersonate;
  • workload identity federation with a service_account_impersonation_url, as the service account that URL names, with the federated token calling generateIdToken the way it calls generateAccessToken for access tokens.

Fails with ErrorKind::IdTokenNeedsImpersonation for credentials that hold no service account: authorized_user and external_account_authorized_user credentials, workload identity federation without impersonation, and gdch_service_account credentials. Use id_token_impersonating for the first three.

Fails with ErrorKind::CryptoProviderMissing for a service account key, used directly or as the source of an impersonation, when the auth-default-crypto feature is off and no rustls crypto provider is installed.

Source

pub async fn id_token_impersonating( audience: &IdTokenAudience, service_account: &ServiceAccountEmail, source_credentials: Credentials, ) -> Result<Self>

ID tokens for audience, minted with the identity of service_account through the IAM Credentials generateIdToken method, called with the access tokens of source_credentials. Their principal needs the iam.serviceAccounts.getOpenIdToken permission on service_account, which the Service Account OpenID Connect Identity Token Creator role grants.

source_credentials built from a service account key sign with it, and need a rustls crypto provider when the auth-default-crypto feature is off. They are opaque here, so this constructor cannot check for one.

Source

pub async fn from_adc() -> Result<Self>

Access tokens for the cloud-platform scope, minted with the Application Default Credentials: from_adc_with_scopes with GCP_DEFAULT_SCOPES.

Source

pub async fn from_adc_with_scopes(scopes: Vec<String>) -> Result<Self>

Access tokens for scopes, minted with the Application Default Credentials.

Fails with ErrorKind::CryptoProviderMissing for a service account key, used directly or as the source of an impersonation, when the auth-default-crypto feature is off and no rustls crypto provider is installed. Credentials built with google-cloud-auth’s Builder and converted with GoogleAuthHeaders::from are not checked, and a missing provider panics in their refresh task instead.

Source

pub async fn headers(&self) -> Result<Arc<HeaderMap>>

The headers to set on a request, replacing any it carries under the same names.

Trait Implementations§

Source§

impl Debug for GoogleAuthHeaders

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Credentials> for GoogleAuthHeaders

Access tokens, or whatever headers credentials serve.

credentials built from a service account key need a rustls crypto provider when the auth-default-crypto feature is off. They are opaque here, so this conversion cannot check for one; GoogleAuthHeaders::from_adc_with_scopes checks for Application Default Credentials.

Source§

fn from(credentials: Credentials) -> Self

Converts to this type from the input type.
Source§

impl From<IDTokenCredentials> for GoogleAuthHeaders

ID tokens from any google-cloud-auth ID token credentials, such as idtoken::service_account::Builder builds from a key that is not the Application Default Credentials.

ID token credentials built from a service account key need a rustls crypto provider when the auth-default-crypto feature is off. They are opaque here, so this conversion cannot check for one; GoogleAuthHeaders::id_token_from_adc checks for Application Default Credentials.

Source§

fn from(credentials: IDTokenCredentials) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more