A lexicon-driven AppView for ATProto. happyview.dev
backfill firehose jetstream atproto appview oauth lexicon
8
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add support for redirect uri on auth

Trezy 4ae00ade 540a14ef

+38 -9
+38 -9
src/auth/routes.rs
··· 12 12 use crate::db::adapt_sql; 13 13 use crate::error::AppError; 14 14 15 + const REDIRECT_COOKIE_NAME: &str = "happyview_redirect"; 16 + 15 17 #[derive(Deserialize)] 16 18 pub struct LoginQuery { 17 19 handle: String, 20 + redirect_uri: Option<String>, 18 21 } 19 22 20 23 #[derive(Deserialize)] ··· 34 37 35 38 async fn login( 36 39 State(state): State<AppState>, 40 + jar: SignedCookieJar<Key>, 37 41 Query(query): Query<LoginQuery>, 38 - ) -> Result<Json<serde_json::Value>, AppError> { 42 + ) -> Result<(SignedCookieJar<Key>, Json<serde_json::Value>), AppError> { 39 43 let url = state 40 44 .oauth 41 45 .authorize(&query.handle, Default::default()) 42 46 .await 43 47 .map_err(|e| AppError::Internal(format!("OAuth authorize failed: {e}")))?; 44 48 45 - Ok(Json(serde_json::json!({ "url": url }))) 49 + // Store the redirect URI in a cookie if provided 50 + let jar = if let Some(redirect_uri) = query.redirect_uri { 51 + let mut cookie = Cookie::new(REDIRECT_COOKIE_NAME, redirect_uri); 52 + cookie.set_path("/"); 53 + cookie.set_http_only(true); 54 + cookie.set_same_site(axum_extra::extract::cookie::SameSite::Lax); 55 + if state.config.public_url.starts_with("https") { 56 + cookie.set_secure(true); 57 + } 58 + jar.add(cookie) 59 + } else { 60 + jar 61 + }; 62 + 63 + Ok((jar, Json(serde_json::json!({ "url": url })))) 46 64 } 47 65 48 66 async fn callback( ··· 68 86 .await 69 87 .ok_or_else(|| AppError::Internal("no DID in OAuth session".into()))?; 70 88 71 - let mut cookie = Cookie::new(COOKIE_NAME, did.to_string()); 72 - cookie.set_path("/"); 73 - cookie.set_http_only(true); 74 - cookie.set_same_site(axum_extra::extract::cookie::SameSite::Lax); 89 + // Get the redirect URL from cookie, defaulting to "/" 90 + let redirect_url = jar 91 + .get(REDIRECT_COOKIE_NAME) 92 + .map(|c| c.value().to_string()) 93 + .unwrap_or_else(|| "/".to_string()); 94 + 95 + // Set the session cookie 96 + let mut session_cookie = Cookie::new(COOKIE_NAME, did.to_string()); 97 + session_cookie.set_path("/"); 98 + session_cookie.set_http_only(true); 99 + session_cookie.set_same_site(axum_extra::extract::cookie::SameSite::Lax); 75 100 if state.config.public_url.starts_with("https") { 76 - cookie.set_secure(true); 101 + session_cookie.set_secure(true); 77 102 } 78 103 79 - let jar = jar.add(cookie); 80 - Ok((jar, Redirect::to("/"))) 104 + // Remove the redirect cookie 105 + let mut redirect_removal = Cookie::from(REDIRECT_COOKIE_NAME); 106 + redirect_removal.set_path("/"); 107 + 108 + let jar = jar.add(session_cookie).remove(redirect_removal); 109 + Ok((jar, Redirect::to(&redirect_url))) 81 110 } 82 111 83 112 async fn logout(