1#![forbid(unsafe_code)]
10#![warn(missing_docs, rust_2018_idioms)]
11
12pub mod error;
13pub mod provider;
14pub mod flow;
15pub mod token;
16pub mod session;
17
18pub use error::{AuthError, Result};
19pub use provider::{OAuthProvider, ProviderConfig, ProviderType};
20pub use flow::{AuthFlow, AuthState, DeviceAuthFlow};
21pub use token::{TokenSet, TokenValidator, UserInfo};
22pub use session::{AuthSession, AuthSessionManager};
23
24use secrecy::{Secret, SecretString};
25
26#[derive(Clone)]
28pub enum KnownProvider {
29 Google {
31 client_id: String,
33 client_secret: SecretString,
35 allowed_domain: Option<String>,
37 },
38 Microsoft {
40 client_id: String,
42 client_secret: SecretString,
44 tenant_id: String,
46 },
47 Okta {
49 client_id: String,
51 client_secret: SecretString,
53 domain: String,
55 auth_server_id: Option<String>,
57 },
58 Generic {
60 name: String,
62 client_id: String,
64 client_secret: SecretString,
66 issuer_url: String,
68 },
69}
70
71impl KnownProvider {
72 pub fn issuer_url(&self) -> String {
74 match self {
75 KnownProvider::Google { .. } => "https://accounts.google.com".to_string(),
76 KnownProvider::Microsoft { tenant_id, .. } => {
77 format!("https://login.microsoftonline.com/{}/v2.0", tenant_id)
78 }
79 KnownProvider::Okta { domain, auth_server_id, .. } => {
80 match auth_server_id {
81 Some(id) => format!("https://{}/oauth2/{}", domain, id),
82 None => format!("https://{}/oauth2/default", domain),
83 }
84 }
85 KnownProvider::Generic { issuer_url, .. } => issuer_url.clone(),
86 }
87 }
88
89 pub fn client_id(&self) -> &str {
91 match self {
92 KnownProvider::Google { client_id, .. } => client_id,
93 KnownProvider::Microsoft { client_id, .. } => client_id,
94 KnownProvider::Okta { client_id, .. } => client_id,
95 KnownProvider::Generic { client_id, .. } => client_id,
96 }
97 }
98
99 pub fn client_secret(&self) -> &SecretString {
101 match self {
102 KnownProvider::Google { client_secret, .. } => client_secret,
103 KnownProvider::Microsoft { client_secret, .. } => client_secret,
104 KnownProvider::Okta { client_secret, .. } => client_secret,
105 KnownProvider::Generic { client_secret, .. } => client_secret,
106 }
107 }
108
109 pub fn provider_type(&self) -> &'static str {
111 match self {
112 KnownProvider::Google { .. } => "google",
113 KnownProvider::Microsoft { .. } => "microsoft",
114 KnownProvider::Okta { .. } => "okta",
115 KnownProvider::Generic { .. } => "generic",
116 }
117 }
118}