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
24#[derive(Debug, Clone)]
26pub enum KnownProvider {
27 Google {
29 client_id: String,
31 client_secret: String,
33 allowed_domain: Option<String>,
35 },
36 Microsoft {
38 client_id: String,
40 client_secret: String,
42 tenant_id: String,
44 },
45 Okta {
47 client_id: String,
49 client_secret: String,
51 domain: String,
53 auth_server_id: Option<String>,
55 },
56 Generic {
58 name: String,
60 client_id: String,
62 client_secret: String,
64 issuer_url: String,
66 },
67}
68
69impl KnownProvider {
70 pub fn issuer_url(&self) -> String {
72 match self {
73 KnownProvider::Google { .. } => "https://accounts.google.com".to_string(),
74 KnownProvider::Microsoft { tenant_id, .. } => {
75 format!("https://login.microsoftonline.com/{}/v2.0", tenant_id)
76 }
77 KnownProvider::Okta { domain, auth_server_id, .. } => {
78 match auth_server_id {
79 Some(id) => format!("https://{}/oauth2/{}", domain, id),
80 None => format!("https://{}/oauth2/default", domain),
81 }
82 }
83 KnownProvider::Generic { issuer_url, .. } => issuer_url.clone(),
84 }
85 }
86
87 pub fn client_id(&self) -> &str {
89 match self {
90 KnownProvider::Google { client_id, .. } => client_id,
91 KnownProvider::Microsoft { client_id, .. } => client_id,
92 KnownProvider::Okta { client_id, .. } => client_id,
93 KnownProvider::Generic { client_id, .. } => client_id,
94 }
95 }
96
97 pub fn client_secret(&self) -> &str {
99 match self {
100 KnownProvider::Google { client_secret, .. } => client_secret,
101 KnownProvider::Microsoft { client_secret, .. } => client_secret,
102 KnownProvider::Okta { client_secret, .. } => client_secret,
103 KnownProvider::Generic { client_secret, .. } => client_secret,
104 }
105 }
106
107 pub fn provider_type(&self) -> &'static str {
109 match self {
110 KnownProvider::Google { .. } => "google",
111 KnownProvider::Microsoft { .. } => "microsoft",
112 KnownProvider::Okta { .. } => "okta",
113 KnownProvider::Generic { .. } => "generic",
114 }
115 }
116}