Skip to content

Commit

Permalink
fix: remove the rest of the specific cookie handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed May 25, 2024
1 parent 0fa1d7c commit 764f18f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 37 deletions.
1 change: 0 additions & 1 deletion .env.local
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
BACKEND_URL="http://127.0.0.1:8080"
BACKEND_SECRET="temporarydevelopmentkey"
RAUTHY_URL="http://localhost:8921"
PUBLIC_COOKIE_PREFIX="" # Set this to `__HOST-` in production
RAUTHY_USERATTRIBUTES_API_KEY="userattributes$very_bad_secret_use_only_in_development_qH6udD97p1hEXOxqFWoZwxAjl"
SMTP_HOST="localhost"
SMTP_PORT="2525"
Expand Down
53 changes: 20 additions & 33 deletions backend/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use axum::{
extract::{FromRequest, Request},
BoxError,
};
use axum_extra::extract::CookieJar;
use http::StatusCode;
use serde::{Deserialize, Serialize};

Expand All @@ -21,39 +20,27 @@ where
type Rejection = ();

async fn from_request(req: Request, _: &S) -> Result<Self, Self::Rejection> {
let cookies = CookieJar::from_headers(req.headers());
let rauthy_session = cookies.get(&format!("{}RauthySession", ARGS.cookie_prefix));
let session = async move {
if let Some(session) = rauthy_session {
let session_info = CLIENT
.get(ARGS.rauthy_url.join("/auth/v1/oidc/sessioninfo").unwrap())
.header(
"Cookie",
format!("{}RauthySession={}", ARGS.cookie_prefix, session.value()),
)
.send()
.await?;
let session_info = session_info.json::<RauthySessionInfo>().await?;
let user_info = CLIENT
.get(
ARGS.rauthy_url
.join(&format!("/auth/v1/users/{}", session_info.user_id))
.unwrap(),
)
.header(
"Cookie",
format!("{}RauthySession={}", ARGS.cookie_prefix, session.value()),
)
.send()
.await?;
let user_info = user_info.json::<RauthyUserInfo>().await?;
Ok::<_, reqwest::Error>(Some(RauthySession {
info: session_info,
user: user_info,
}))
} else {
Ok(None)
}
let session_info = CLIENT
.get(ARGS.rauthy_url.join("/auth/v1/oidc/sessioninfo").unwrap())
.headers(req.headers().clone())
.send()
.await?;
let session_info = session_info.json::<RauthySessionInfo>().await?;
let user_info = CLIENT
.get(
ARGS.rauthy_url
.join(&format!("/auth/v1/users/{}", session_info.user_id))
.unwrap(),
)
.headers(req.headers().clone())
.send()
.await?;
let user_info = user_info.json::<RauthyUserInfo>().await?;
Ok::<_, reqwest::Error>(Some(RauthySession {
info: session_info,
user: user_info,
}))
}
.await;
if let Err(e) = &session {
Expand Down
3 changes: 0 additions & 3 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ pub struct Args {
pub data_dir: PathBuf,
#[arg(default_value = "http://localhost:8921", env)]
pub rauthy_url: Url,
/// Set this to `__Host-` if using Rauthy in production with host-scope cookies
#[arg(default_value = "", env)]
pub cookie_prefix: String,
}

pub static ARGS: Lazy<Args> = Lazy::new(Args::parse);
Expand Down

0 comments on commit 764f18f

Please sign in to comment.