Skip to main content

ServiceAccountTokenCredentialProvider

Struct ServiceAccountTokenCredentialProvider 

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

Exchanges a service-account credential for an OAuth access token.

The provider returns a token-only Credential with a non-optional absolute expiration and preserves the source service account email as signer identity. This makes service-account JSON loaded by providers such as super::FileCredentialProvider usable as the source of a Google credential granter without requiring the host application to implement the JWT bearer exchange.

The provider performs an OAuth exchange on every call. Cache and refresh behavior remains owned by the outer reqsign_core::Signer or reqsign_core::Granter. It is not inserted into the default credential provider chain.

§Example

use reqsign_core::{Context, Granter};
use reqsign_google::{
    CredentialAccessBoundaryGrant, CredentialAccessBoundaryPermissions,
    FileCredentialProvider, ServerSideCredentialAccessBoundaryGranter,
    ServiceAccountTokenCredentialProvider,
};

let source = ServiceAccountTokenCredentialProvider::from_provider(
    FileCredentialProvider::new("/path/to/service-account.json"),
);
let grant = CredentialAccessBoundaryGrant::for_object_prefix(
    "example-bucket",
    "customer-a/",
    CredentialAccessBoundaryPermissions::OBJECT_VIEWER,
);
let credential = Granter::new(
    context,
    source,
    ServerSideCredentialAccessBoundaryGranter::new(grant),
)
.grant(None)
.await?;

Implementations§

Source§

impl ServiceAccountTokenCredentialProvider

Source

pub fn new(service_account: ServiceAccount) -> Self

Create a provider bound to one service account.

Source

pub fn from_provider( provider: impl ProvideCredential<Credential = Credential> + 'static, ) -> Self

Create a provider that loads its service account from another provider.

None from the source provider is preserved. A returned credential must contain a valid service account; other credential variants are rejected before the OAuth request is sent.

Source

pub fn with_scope(self, scope: impl Into<String>) -> Self

Set the OAuth scope.

This value takes precedence over GOOGLE_SCOPE. When neither is set, the Google Cloud platform scope is used.

Trait Implementations§

Source§

impl Debug for ServiceAccountTokenCredentialProvider

Source§

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

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

impl ProvideCredential for ServiceAccountTokenCredentialProvider

Source§

type Credential = Credential

Credential returned by this loader. Read more
Source§

async fn provide_credential( &self, ctx: &Context, ) -> Result<Option<Self::Credential>>

Load signing credential from current env.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> MaybeSend for T
where T: Send,

Source§

impl<T> ProvideCredentialDyn for T

Source§

type Credential = <T as ProvideCredential>::Credential

Credential returned by this loader.
Source§

fn provide_credential_dyn<'a>( &'a self, ctx: &'a Context, ) -> Pin<Box<dyn Future<Output = Result<Option<<T as ProvideCredentialDyn>::Credential>, Error>> + Send + 'a>>

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V