Module auth

Source
Expand description

§Authentication Module

Comprehensive authentication system for Azure Service Bus operations supporting multiple authentication methods and providers. This module provides a flexible architecture that can handle various Azure authentication scenarios.

§Supported Authentication Methods

§Azure Active Directory (Azure AD)

  • Device Code Flow - Interactive authentication for CLI applications
  • Client Credentials Flow - Service principal authentication for automated scenarios

§Connection String Authentication

  • Shared Access Signature (SAS) - Token-based authentication using connection strings
  • Automatic SAS Token Generation - Time-limited tokens with configurable expiration

§Architecture Overview

The authentication system is built around several key components:

§Authentication Providers

§Azure AD Provider

use quetty_server::auth::{AzureAdProvider, AzureAdAuthConfig};

let config = AzureAdAuthConfig {
    auth_method: "device_code".to_string(),
    tenant_id: Some("your-tenant-id".to_string()),
    client_id: Some("your-client-id".to_string()),
    ..Default::default()
};

let provider = AzureAdProvider::new(config, http_client)?;
let token = provider.authenticate().await?;

§Connection String Provider

use quetty_server::auth::{ConnectionStringProvider, ConnectionStringConfig};

let config = ConnectionStringConfig {
    value: "Endpoint=sb://test.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=...".to_string(),
};

let provider = ConnectionStringProvider::new(config)?;
let token = provider.authenticate().await?;

§State Management

The AuthStateManager provides centralized authentication state:

use quetty_server::auth::AuthStateManager;
use std::sync::Arc;

let auth_manager = Arc::new(AuthStateManager::new());

// Check authentication status
if auth_manager.is_authenticated().await {
    println!("Already authenticated");
}

// Start automatic token refresh
auth_manager.clone().start_refresh_service().await;

§Token Caching

Automatic token caching with expiration management:

use quetty_server::auth::TokenCache;

let cache = TokenCache::new();

// Check if token needs refresh
if cache.needs_refresh("user_token").await {
    // Refresh token...
}

§Integration with Service Bus

The authentication system integrates seamlessly with Service Bus operations:

use quetty_server::auth::{create_service_bus_auth_provider, get_azure_ad_token_with_auth};

// Create provider for Service Bus
let provider = create_service_bus_auth_provider(
    "azure_ad",
    None,
    &azure_config,
    http_client
)?;

// Get token for operations
let token = get_azure_ad_token_with_auth(&provider).await?;

Re-exports§

pub use auth_setup::create_auth_provider;
pub use auth_setup::set_global_auth_state;
pub use auth_state::AuthStateManager;
pub use auth_state::AuthenticationState;
pub use azure_ad::AzureAdProvider;
pub use azure_ad::DeviceCodeFlowInfo;
pub use connection_string::ConnectionStringProvider;
pub use errors::TokenRefreshError;
pub use provider::AuthProvider;
pub use provider::AuthToken;
pub use sas_token_generator::SasTokenGenerator;
pub use service_bus_auth::create_auth_provider as create_service_bus_auth_provider;
pub use service_bus_auth::get_azure_ad_token_with_auth;
pub use token_cache::TokenCache;
pub use token_refresh_service::TokenRefreshService;
pub use types::AuthConfig;
pub use types::AuthType;
pub use types::DeviceCodeInfo;

Modules§

auth_provider
auth_setup
Authentication setup and global state management.
auth_state
azure_ad
connection_string
errors
provider
sas_token_generator
service_bus_auth
Service Bus authentication provider creation and management.
token_cache
token_refresh_service
types