mirror of
https://codeberg.org/pfzetto/axum-oidc
synced 2025-12-08 06:05:16 +01:00
fix: #32 use OriginalUri for redirect_url
This commit is contained in:
parent
bacab1c939
commit
861cb70cee
3 changed files with 19 additions and 3 deletions
|
|
@ -14,7 +14,7 @@ keywords = [ "axum", "oidc", "openidconnect", "authentication" ]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
thiserror = "2.0"
|
thiserror = "2.0"
|
||||||
axum-core = "0.5"
|
axum-core = "0.5"
|
||||||
axum = { version = "0.8", default-features = false, features = [ "query" ] }
|
axum = { version = "0.8", default-features = false, features = [ "query", "original-uri" ] }
|
||||||
tower-service = "0.3"
|
tower-service = "0.3"
|
||||||
tower-layer = "0.3"
|
tower-layer = "0.3"
|
||||||
tower-sessions = { version = "0.14", default-features = false, features = [ "axum-core" ] }
|
tower-sessions = { version = "0.14", default-features = false, features = [ "axum-core" ] }
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,9 @@ pub enum MiddlewareError {
|
||||||
|
|
||||||
#[error("auth middleware not found")]
|
#[error("auth middleware not found")]
|
||||||
AuthMiddlewareNotFound,
|
AuthMiddlewareNotFound,
|
||||||
|
|
||||||
|
#[error("original url not found")]
|
||||||
|
OriginalUrlNotFound,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,10 @@ use std::{
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
|
|
||||||
use axum::response::{IntoResponse, Redirect};
|
use axum::{
|
||||||
|
extract::OriginalUri,
|
||||||
|
response::{IntoResponse, Redirect},
|
||||||
|
};
|
||||||
use axum_core::response::Response;
|
use axum_core::response::Response;
|
||||||
use futures_util::future::BoxFuture;
|
use futures_util::future::BoxFuture;
|
||||||
use http::{request::Parts, Request};
|
use http::{request::Parts, Request};
|
||||||
|
|
@ -115,6 +118,16 @@ where
|
||||||
.get::<Session>()
|
.get::<Session>()
|
||||||
.ok_or(MiddlewareError::SessionNotFound)?;
|
.ok_or(MiddlewareError::SessionNotFound)?;
|
||||||
|
|
||||||
|
let redirect_url = parts
|
||||||
|
.extensions
|
||||||
|
.get::<OriginalUri>()
|
||||||
|
.ok_or(MiddlewareError::OriginalUrlNotFound)?;
|
||||||
|
|
||||||
|
let redirect_url = if let Some(query) = redirect_url.query() {
|
||||||
|
redirect_url.path().to_string() + "?" + query
|
||||||
|
} else {
|
||||||
|
redirect_url.path().to_string()
|
||||||
|
};
|
||||||
// generate a login url and redirect the user to it
|
// generate a login url and redirect the user to it
|
||||||
|
|
||||||
let (pkce_challenge, pkce_verifier) = PkceCodeChallenge::new_random_sha256();
|
let (pkce_challenge, pkce_verifier) = PkceCodeChallenge::new_random_sha256();
|
||||||
|
|
@ -143,7 +156,7 @@ where
|
||||||
pkce_verifier,
|
pkce_verifier,
|
||||||
authenticated: None,
|
authenticated: None,
|
||||||
refresh_token: None,
|
refresh_token: None,
|
||||||
redirect_url: parts.uri.to_string().into(),
|
redirect_url: redirect_url.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
session.insert(SESSION_KEY, oidc_session).await?;
|
session.insert(SESSION_KEY, oidc_session).await?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue