SubjectTokenProvider

Trait SubjectTokenProvider 

Source
pub trait SubjectTokenProvider:
    Debug
    + Send
    + Sync {
    type Error: SubjectTokenProviderError;

    // Required method
    fn subject_token(
        &self,
    ) -> impl Future<Output = Result<SubjectToken, Self::Error>> + Send;
}
Expand description

Trait for providing a third-party subject token.

The Google Cloud client libraries for Rust will automatically implement this trait for external account credentials. You might need to implement this trait for advanced authentication scenarios where you want to integrate a custom subject token fetching mechanism.

§Example

#[derive(Debug)]
struct CustomProviderError {
    message: String,
    is_transient: bool,
}

impl fmt::Display for CustomProviderError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "CustomProviderError: {}", self.message)
    }
}

impl Error for CustomProviderError {}

impl SubjectTokenProviderError for CustomProviderError {
    fn is_transient(&self) -> bool {
        self.is_transient
    }
}

#[derive(Debug)]
struct MyCustomProvider {
    api_key: String,
}

impl SubjectTokenProvider for MyCustomProvider {
    type Error = CustomProviderError;

    async fn subject_token(&self) -> Result<SubjectToken, Self::Error> {
            let token_from_idp = "a-very-secret-token-from-your-idp";
            Ok(SubjectTokenBuilder::new(token_from_idp.to_string()).build())
    }
}

Required Associated Types§

Source

type Error: SubjectTokenProviderError

The error type that can be returned by this provider.

The error must implement the SubjectTokenProviderError trait to allow the authentication client to know whether the error is transient and can be retried.

Required Methods§

Source

fn subject_token( &self, ) -> impl Future<Output = Result<SubjectToken, Self::Error>> + Send

Asynchronously fetches the third-party subject token.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§