Added first implementation of RP Initiated Logout

Created a new extractor for RP-Initiated-Logout and modified example to
use it.
This commit is contained in:
Paul Zinselmeyer 2024-03-25 17:20:44 +01:00
parent a522b7936d
commit 1844b880c1
Signed by: pfzetto
GPG key ID: B471A1AF06C895FD
8 changed files with 171 additions and 17 deletions

View file

@ -3,6 +3,7 @@ use axum::{
};
use axum_oidc::{
error::MiddlewareError, EmptyAdditionalClaims, OidcAuthLayer, OidcClaims, OidcLoginLayer,
OidcRpInitiatedLogout,
};
use tokio::net::TcpListener;
use tower::ServiceBuilder;
@ -13,6 +14,12 @@ use tower_sessions::{
#[tokio::main]
async fn main() {
dotenvy::dotenv().ok();
let app_url = std::env::var("APP_URL").expect("APP_URL env variable");
let issuer = std::env::var("ISSUER").expect("ISSUER env variable");
let client_id = std::env::var("CLIENT_ID").expect("CLIENT_ID env variable");
let client_secret = std::env::var("CLIENT_SECRET").ok();
let session_store = MemoryStore::default();
let session_layer = SessionManagerLayer::new(session_store)
.with_secure(false)
@ -31,10 +38,10 @@ async fn main() {
}))
.layer(
OidcAuthLayer::<EmptyAdditionalClaims>::discover_client(
Uri::from_static("https://app.example.com"),
"https://auth.example.com/auth/realms/example".to_string(),
"my-client".to_string(),
Some("123456".to_owned()),
Uri::from_maybe_shared(app_url).expect("valid APP_URL"),
issuer,
client_id,
client_secret,
vec![],
)
.await
@ -43,6 +50,7 @@ async fn main() {
let app = Router::new()
.route("/foo", get(authenticated))
.route("/logout", get(logout))
.layer(oidc_login_service)
.route("/bar", get(maybe_authenticated))
.layer(oidc_auth_service)
@ -70,3 +78,7 @@ async fn maybe_authenticated(
"Hello anon!".to_string()
}
}
async fn logout(logout: OidcRpInitiatedLogout) -> impl IntoResponse {
logout.with_post_logout_redirect(Uri::from_static("https://google.de"))
}