pub struct AzureAdProvider { /* private fields */ }Expand description
Authentication provider for Azure Active Directory authentication flows.
Supports both Device Code Flow (for interactive scenarios) and Client Credentials Flow (for service-to-service authentication). This provider handles the complete OAuth 2.0 authentication process with Azure AD.
§Supported Flows
- Device Code Flow - Interactive authentication where users enter a code on a separate device
- Client Credentials Flow - Service principal authentication using client ID and secret
§Examples
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 client = reqwest::Client::new();
let provider = AzureAdProvider::new(config, client)?;
let token = provider.authenticate().await?;Implementations§
Source§impl AzureAdProvider
impl AzureAdProvider
Sourcepub fn new(
config: AzureAdAuthConfig,
http_client: Client,
) -> Result<Self, ServiceBusError>
pub fn new( config: AzureAdAuthConfig, http_client: Client, ) -> Result<Self, ServiceBusError>
Creates a new AzureAdProvider with the specified configuration and HTTP client.
§Arguments
config- Azure AD authentication configurationhttp_client- HTTP client for making authentication requests
§Returns
A configured AzureAdProvider ready for authentication
§Examples
use quetty_server::auth::{AzureAdProvider, AzureAdAuthConfig};
let config = AzureAdAuthConfig::default();
let client = reqwest::Client::new();
let provider = AzureAdProvider::new(config, client)?;Sourcepub fn flow_type(&self) -> &str
pub fn flow_type(&self) -> &str
Gets the configured authentication flow type.
§Returns
The authentication method string (“device_code” or “client_secret”)
Sourcepub async fn start_device_code_flow(
&self,
) -> Result<DeviceCodeFlowInfo, ServiceBusError>
pub async fn start_device_code_flow( &self, ) -> Result<DeviceCodeFlowInfo, ServiceBusError>
Initiates a Device Code Flow authentication process.
This method starts the device code flow by requesting a device code from Azure AD. The returned information should be displayed to the user so they can complete authentication on a separate device or browser.
§Returns
DeviceCodeFlowInfo containing the user code, verification URL, and other details
§Errors
Returns ServiceBusError::AuthenticationError if:
- The device code request fails
- Invalid client configuration
- Network connectivity issues
§Examples
use quetty_server::auth::AzureAdProvider;
let provider = AzureAdProvider::new(config, client)?;
let device_info = provider.start_device_code_flow().await?;
println!("Go to: {}", device_info.verification_uri);
println!("Enter code: {}", device_info.user_code);Sourcepub async fn poll_device_code_token(
&self,
device_info: &DeviceCodeFlowInfo,
) -> Result<AuthToken, ServiceBusError>
pub async fn poll_device_code_token( &self, device_info: &DeviceCodeFlowInfo, ) -> Result<AuthToken, ServiceBusError>
Polls Azure AD for completion of device code authentication.
This method continuously polls Azure AD to check if the user has completed the device code authentication process. It handles all the standard OAuth 2.0 device flow polling logic including backoff and error handling.
§Arguments
device_info- Device code information from [start_device_code_flow]
§Returns
An AuthToken when authentication is successfully completed
§Errors
Returns ServiceBusError::AuthenticationError if:
- Authentication times out or expires
- User denies access
- Network errors during polling
§Examples
use quetty_server::auth::AzureAdProvider;
let provider = AzureAdProvider::new(config, client)?;
let device_info = provider.start_device_code_flow().await?;
// Display info to user...
let token = provider.poll_device_code_token(&device_info).await?;Trait Implementations§
Source§impl AuthProvider for AzureAdProvider
impl AuthProvider for AzureAdProvider
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,
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,
Authenticates using the configured Azure AD authentication flow.
Automatically selects the appropriate authentication method based on the configuration (device_code or client_secret) and handles the complete OAuth 2.0 flow including error handling and token retrieval.
§Returns
An AuthToken containing the Azure AD access token and metadata
§Errors
Returns ServiceBusError if:
- Authentication method is not supported
- Authentication flow fails
- Network connectivity issues
- Invalid credentials or configuration
Source§fn auth_type(&self) -> AuthType
fn auth_type(&self) -> AuthType
Returns the authentication type for this provider.
§Returns
AuthType::AzureAd indicating Azure Active Directory authentication
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,
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,
Source§fn requires_refresh(&self) -> bool
fn requires_refresh(&self) -> bool
Source§impl Clone for AzureAdProvider
impl Clone for AzureAdProvider
Source§fn clone(&self) -> AzureAdProvider
fn clone(&self) -> AzureAdProvider
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more