diff options
Diffstat (limited to 'src/oauth')
| -rw-r--r-- | src/oauth/mod.rs | 2 | ||||
| -rw-r--r-- | src/oauth/server.rs | 18 | ||||
| -rw-r--r-- | src/oauth/types.rs | 2 |
3 files changed, 14 insertions, 8 deletions
diff --git a/src/oauth/mod.rs b/src/oauth/mod.rs index d6717c2..3a0d861 100644 --- a/src/oauth/mod.rs +++ b/src/oauth/mod.rs @@ -2,4 +2,4 @@ pub mod server; pub mod types; pub use server::OAuthServer; -pub use types::{AuthCode, Claims, ErrorResponse, TokenResponse};
\ No newline at end of file +pub use types::{AuthCode, Claims, ErrorResponse, TokenResponse}; diff --git a/src/oauth/server.rs b/src/oauth/server.rs index 3ee0bb3..243fdba 100644 --- a/src/oauth/server.rs +++ b/src/oauth/server.rs @@ -1,8 +1,8 @@ -use crate::clients::{ClientManager, parse_basic_auth}; +use crate::clients::{parse_basic_auth, ClientManager}; use crate::config::Config; use crate::keys::KeyManager; use crate::oauth::types::{AuthCode, Claims, ErrorResponse, TokenResponse}; -use jsonwebtoken::{Algorithm, Header, encode}; +use jsonwebtoken::{encode, Algorithm, Header}; use std::collections::HashMap; use std::time::{SystemTime, UNIX_EPOCH}; use url::Url; @@ -51,7 +51,8 @@ impl OAuthServer { // Validate client exists let client_manager = self.client_manager.lock().unwrap(); - let _client = client_manager.get_client(client_id) + let _client = client_manager + .get_client(client_id) .ok_or_else(|| self.error_response("invalid_client", "Invalid client_id"))?; // Validate redirect URI is registered for this client @@ -104,7 +105,11 @@ impl OAuthServer { Ok(redirect_url.to_string()) } - pub fn handle_token(&self, params: &HashMap<String, String>, auth_header: Option<&str>) -> Result<String, String> { + pub fn handle_token( + &self, + params: &HashMap<String, String>, + auth_header: Option<&str>, + ) -> Result<String, String> { let grant_type = params .get("grant_type") .ok_or_else(|| self.error_response("invalid_request", "Missing grant_type"))?; @@ -124,8 +129,9 @@ impl OAuthServer { // Clients can authenticate via HTTP Basic Auth or form parameters let (client_id, client_secret) = if let Some(auth_header) = auth_header { // HTTP Basic Authentication (preferred method) - parse_basic_auth(auth_header) - .ok_or_else(|| self.error_response("invalid_client", "Invalid Authorization header"))? + parse_basic_auth(auth_header).ok_or_else(|| { + self.error_response("invalid_client", "Invalid Authorization header") + })? } else { // Form-based authentication (fallback) let client_id = params diff --git a/src/oauth/types.rs b/src/oauth/types.rs index 685af02..6c62edf 100644 --- a/src/oauth/types.rs +++ b/src/oauth/types.rs @@ -36,4 +36,4 @@ pub struct AuthCode { pub scope: Option<String>, pub expires_at: u64, pub user_id: String, -}
\ No newline at end of file +} |
