feat: Maximus Account OAuth2 + machine activation (#51, #53) #65

Merged
maximus merged 7 commits from issue-51-compte-maximus-oauth into main 2026-04-10 19:38:28 +00:00
2 changed files with 5 additions and 3 deletions
Showing only changes of commit be5f6a55c5 - Show all commits

View file

@ -136,7 +136,7 @@ pub fn start_oauth(app: tauri::AppHandle) -> Result<String, String> {
// Store verifier in managed state // Store verifier in managed state
let state = app.state::<OAuthState>(); let state = app.state::<OAuthState>();
*state.code_verifier.lock().unwrap() = Some(verifier); *state.code_verifier.lock().map_err(|e| format!("Mutex poisoned: {}", e))? = Some(verifier);
let endpoint = logto_endpoint(); let endpoint = logto_endpoint();
let client_id = logto_app_id(); let client_id = logto_app_id();
@ -157,7 +157,7 @@ pub fn start_oauth(app: tauri::AppHandle) -> Result<String, String> {
pub async fn handle_auth_callback(app: tauri::AppHandle, code: String) -> Result<AccountInfo, String> { pub async fn handle_auth_callback(app: tauri::AppHandle, code: String) -> Result<AccountInfo, String> {
let verifier = { let verifier = {
let state = app.state::<OAuthState>(); let state = app.state::<OAuthState>();
let verifier = state.code_verifier.lock().unwrap().take(); let verifier = state.code_verifier.lock().map_err(|e| format!("Mutex poisoned: {}", e))?.take();
verifier.ok_or("No pending OAuth flow (verifier missing)")? verifier.ok_or("No pending OAuth flow (verifier missing)")?
}; };

View file

@ -178,7 +178,9 @@ fn extract_auth_code(url: &str) -> Option<String> {
for pair in query.split('&') { for pair in query.split('&') {
let mut kv = pair.splitn(2, '='); let mut kv = pair.splitn(2, '=');
if kv.next()? == "code" { if kv.next()? == "code" {
return kv.next().map(|v| v.to_string()); return kv.next().map(|v| {
urlencoding::decode(v).map(|s| s.into_owned()).unwrap_or_else(|_| v.to_string())
});
} }
} }
None None