1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! Authentication setup and global state management.
//!
//! This module provides functionality for setting up and managing global authentication
//! state that can be shared between the UI and server components. It handles the
//! coordination of authentication providers and state management across the application.
use AuthProvider;
use AuthStateManager;
use AuthProvider as AuthProviderTrait;
use crateServiceBusError;
use ;
/// Global authentication state manager shared across the application.
///
/// This static variable holds the authentication state manager that can be
/// set by the UI and used by server components for authentication operations.
static GLOBAL_AUTH_STATE: = new;
/// Sets the global authentication state manager.
///
/// This function is typically called by the UI component during initialization
/// to establish a shared authentication state that can be used by server
/// components for authentication operations.
///
/// # Arguments
///
/// * `auth_state` - The authentication state manager to set as global
///
/// # Examples
///
/// ```no_run
/// use quetty_server::auth::{AuthStateManager, set_global_auth_state};
/// use std::sync::Arc;
///
/// let auth_state = Arc::new(AuthStateManager::new());
/// set_global_auth_state(auth_state);
/// ```
/// Creates an authentication provider that uses the global authentication state.
///
/// This function creates an [`AuthProvider`] that integrates with the global
/// authentication state manager. It provides a bridge between the UI authentication
/// state and server-side authentication operations.
///
/// # Arguments
///
/// * `fallback_provider` - Optional fallback provider to use if the global state fails
///
/// # Returns
///
/// An [`AuthProvider`] that can be used for authentication operations
///
/// # Errors
///
/// Returns [`ServiceBusError::ConfigurationError`] if:
/// - The global authentication state has not been initialized
/// - The global state is in an invalid state
///
/// # Examples
///
/// ```no_run
/// use quetty_server::auth::{create_auth_provider, set_global_auth_state, AuthStateManager};
/// use std::sync::Arc;
///
/// // First, initialize the global state
/// let auth_state = Arc::new(AuthStateManager::new());
/// set_global_auth_state(auth_state);
///
/// // Then create a provider that uses the global state
/// let provider = create_auth_provider(None)?;
/// let token = provider.authenticate().await?;
/// ```