1pub mod client;
10pub mod discovery;
11pub mod errors;
12pub mod pkce;
13pub mod token;
14pub mod types;
15
16pub use client::*;
17pub use discovery::*;
18pub use errors::*;
19pub use pkce::*;
20pub use token::*;
21pub use types::*;
22
23#[derive(Clone)]
27pub struct AuthConfig {
28 pub enabled: bool,
30
31 pub client_id: Option<String>,
33
34 pub client_secret: Option<String>,
36
37 pub redirect_uri: String,
39
40 pub scopes: Vec<String>,
42
43 pub enable_dynamic_registration: bool,
45}
46
47impl Default for AuthConfig {
48 fn default() -> Self {
49 Self {
50 enabled: false,
51 client_id: None,
52 client_secret: None,
53 redirect_uri: "http://localhost:8080/callback".to_string(),
54 scopes: vec![],
55 enable_dynamic_registration: true,
56 }
57 }
58}
59
60impl AuthConfig {
61 pub fn new() -> Self {
63 Self::default()
64 }
65
66 pub fn with_auth(mut self, enabled: bool) -> Self {
68 self.enabled = enabled;
69 self
70 }
71
72 pub fn with_client_credentials(
74 mut self,
75 client_id: String,
76 client_secret: Option<String>,
77 ) -> Self {
78 self.client_id = Some(client_id);
79 self.client_secret = client_secret;
80 self
81 }
82
83 pub fn with_redirect_uri(mut self, uri: String) -> Self {
85 self.redirect_uri = uri;
86 self
87 }
88
89 pub fn with_scopes(mut self, scopes: Vec<String>) -> Self {
91 self.scopes = scopes;
92 self
93 }
94
95 pub fn generate_state(&self) -> String {
97 use rand::RngExt;
99 let mut rng = rand::rng();
100 let state: String = (0..32)
101 .map(|_| {
102 let idx = rng.random_range(0..62);
103 let chars = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
104 chars[idx] as char
105 })
106 .collect();
107 state
108 }
109}