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
93
94
95
96
//! Multi-provider authentication that tries multiple auth methods in sequence.
use crate;
use async_trait;
use *;
use Arc;
/// Multi-provider authentication that tries providers in order until one succeeds.
///
/// This provider allows supporting multiple authentication methods simultaneously
/// and enables adding custom enterprise authentication providers. Providers are
/// tried in the order they were added via `with_provider()`.
///
/// Provider order matters for authentication precedence - the first successful
/// match wins. Typically, you want faster providers (like API key) before slower
/// ones (like OIDC JWT validation).
///
/// # Example
///
/// ```rust,no_run
/// use micromegas_auth::api_key::{ApiKeyAuthProvider, parse_key_ring};
/// use micromegas_auth::oidc::{OidcAuthProvider, OidcConfig, OidcIssuer};
/// use micromegas_auth::multi::MultiAuthProvider;
/// use std::sync::Arc;
///
/// # async fn example() -> anyhow::Result<()> {
/// // Set up API key provider
/// let keyring = parse_key_ring(r#"[{"name": "test", "key": "secret"}]"#)?;
/// let api_key_provider = Arc::new(ApiKeyAuthProvider::new(keyring));
///
/// // Set up OIDC provider
/// let oidc_config = OidcConfig {
/// issuers: vec![OidcIssuer {
/// issuer: "https://accounts.google.com".to_string(),
/// audience: "your-app.apps.googleusercontent.com".to_string(),
/// }],
/// jwks_refresh_interval_secs: 3600,
/// token_cache_size: 1000,
/// token_cache_ttl_secs: 300,
/// };
/// let oidc_provider = Arc::new(OidcAuthProvider::new(oidc_config).await?);
///
/// // Create multi-provider with builder pattern
/// let multi = MultiAuthProvider::new()
/// .with_provider(api_key_provider)
/// .with_provider(oidc_provider);
/// // .with_provider(Arc::new(MyEnterpriseAuthProvider::new())); // Custom provider!
/// # Ok(())
/// # }
/// ```