Struct gcp_auth::AuthenticationManager
source · [−]pub struct AuthenticationManager { /* private fields */ }
Expand description
Authentication manager is responsible for caching and obtaing credentials for the required scope
Construct the authentication manager with AuthenticationManager::new()
or by creating
a CustomServiceAccount
, then converting it into an AuthenticationManager
using the From
impl.
Implementations
sourceimpl AuthenticationManager
impl AuthenticationManager
sourcepub async fn new() -> Result<Self, Error>
pub async fn new() -> Result<Self, Error>
Finds a service account provider to get authentication tokens from
Tries the following approaches, in order:
- Check if the
GOOGLE_APPLICATION_CREDENTIALS
environment variable if set; if so, use a custom service account as the token source. - Check if the
gcloud
tool is available on thePATH
; if so, use thegcloud auth print-access-token
command as the token source. - Send a HTTP request to the internal metadata server to retrieve a token; if it succeeds, use the default service account as the token source.
- Look for credentials in
.config/gcloud/application_default_credentials.json
; if found, use these credentials to request refresh tokens.
sourcepub async fn get_token(&self, scopes: &[&str]) -> Result<Token, Error>
pub async fn get_token(&self, scopes: &[&str]) -> Result<Token, Error>
Requests Bearer token for the provided scope
Token can be used in the request authorization header in format “Bearer {token}”
sourcepub async fn project_id(&self) -> Result<String, Error>
pub async fn project_id(&self) -> Result<String, Error>
Request the project ID for the authenticating account
This is only available for service account-based authentication methods.
Trait Implementations
sourceimpl From<CustomServiceAccount> for AuthenticationManager
impl From<CustomServiceAccount> for AuthenticationManager
sourcefn from(service_account: CustomServiceAccount) -> Self
fn from(service_account: CustomServiceAccount) -> Self
Converts to this type from the input type.
Auto Trait Implementations
impl !RefUnwindSafe for AuthenticationManager
impl Send for AuthenticationManager
impl Sync for AuthenticationManager
impl Unpin for AuthenticationManager
impl !UnwindSafe for AuthenticationManager
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more