Trait AuthProvider

Source
pub trait AuthProvider: Send + Sync {
    // Required methods
    fn authenticate<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<AuthToken, ServiceBusError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn auth_type(&self) -> AuthType;

    // Provided methods
    fn refresh<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<AuthToken, ServiceBusError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn requires_refresh(&self) -> bool { ... }
}
Expand description

Trait for authentication providers that can obtain Azure AD tokens.

This trait defines the interface for different authentication methods (Device Code Flow, Client Credentials, Connection String) to obtain access tokens for Azure Service Bus operations.

§Examples

use quetty_server::auth::provider::{AuthProvider, AuthToken};
use quetty_server::auth::types::AuthType;
use quetty_server::service_bus_manager::ServiceBusError;
use async_trait::async_trait;

struct MyAuthProvider;

#[async_trait]
impl AuthProvider for MyAuthProvider {
    async fn authenticate(&self) -> Result<AuthToken, ServiceBusError> {
        // Implementation specific authentication logic
        Ok(AuthToken {
            token: "example_token".to_string(),
            token_type: "Bearer".to_string(),
            expires_in_secs: Some(3600),
        })
    }

    fn auth_type(&self) -> AuthType {
        AuthType::AzureAd
    }
}

Required Methods§

Source

fn authenticate<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<AuthToken, ServiceBusError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Performs authentication and returns an access token.

This method should implement the specific authentication flow for the provider (e.g., device code flow, client credentials).

§Errors

Returns ServiceBusError if authentication fails for any reason, including network issues, invalid credentials, or service unavailability.

Source

fn auth_type(&self) -> AuthType

Returns the authentication type used by this provider.

This is used for identifying the authentication method and may affect how the token is used.

Provided Methods§

Source

fn refresh<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<AuthToken, ServiceBusError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Refreshes the authentication token.

Default implementation calls [authenticate] again. Providers that support refresh tokens can override this method for more efficient token renewal.

§Errors

Returns ServiceBusError if token refresh fails.

Source

fn requires_refresh(&self) -> bool

Indicates whether this provider’s tokens require periodic refresh.

Returns true by default. Providers with long-lived tokens (like connection strings) can override this to return false.

Implementors§