mirror of
https://github.com/pfzetto/axum-oidc.git
synced 2025-01-18 04:49:03 +01:00
Merge PR #22
This commit is contained in:
commit
e86842c104
3 changed files with 45 additions and 12 deletions
|
@ -13,13 +13,12 @@ keywords = [ "axum", "oidc", "openidconnect", "authentication" ]
|
|||
|
||||
[dependencies]
|
||||
thiserror = "1.0"
|
||||
axum-core = "0.4"
|
||||
axum = { version = "0.7", default-features = false, features = [ "query" ] }
|
||||
axum-core = "0.5"
|
||||
axum = { version = "0.8", default-features = false, features = [ "query" ] }
|
||||
tower-service = "0.3"
|
||||
tower-layer = "0.3"
|
||||
tower-sessions = { version = "0.13", default-features = false, features = [ "axum-core" ] }
|
||||
http = "1.1"
|
||||
async-trait = "0.1"
|
||||
openidconnect = "3.5"
|
||||
serde = "1.0"
|
||||
futures-util = "0.3"
|
||||
|
|
|
@ -7,7 +7,7 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
tokio = { version = "1.37", features = ["net", "macros", "rt-multi-thread"] }
|
||||
axum = "0.7"
|
||||
axum = { version = "0.8", features = ["macros"] }
|
||||
axum-oidc = { path = "./../.." }
|
||||
tower = "0.4"
|
||||
tower-sessions = "0.13"
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
use std::{borrow::Cow, ops::Deref};
|
||||
use std::{borrow::Cow, convert::Infallible, ops::Deref};
|
||||
|
||||
use crate::{error::ExtractorError, AdditionalClaims, ClearSessionFlag};
|
||||
use async_trait::async_trait;
|
||||
use axum::response::Redirect;
|
||||
use axum_core::{extract::FromRequestParts, response::IntoResponse};
|
||||
use axum_core::{
|
||||
extract::{FromRequestParts, OptionalFromRequestParts},
|
||||
response::IntoResponse,
|
||||
};
|
||||
use http::{request::Parts, uri::PathAndQuery, Uri};
|
||||
use openidconnect::{core::CoreGenderClaim, IdTokenClaims};
|
||||
|
||||
|
@ -13,7 +15,6 @@ use openidconnect::{core::CoreGenderClaim, IdTokenClaims};
|
|||
#[derive(Clone)]
|
||||
pub struct OidcClaims<AC: AdditionalClaims>(pub IdTokenClaims<AC, CoreGenderClaim>);
|
||||
|
||||
#[async_trait]
|
||||
impl<S, AC> FromRequestParts<S> for OidcClaims<AC>
|
||||
where
|
||||
S: Send + Sync,
|
||||
|
@ -30,6 +31,18 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<S, AC> OptionalFromRequestParts<S> for OidcClaims<AC>
|
||||
where
|
||||
S: Send + Sync,
|
||||
AC: AdditionalClaims,
|
||||
{
|
||||
type Rejection = Infallible;
|
||||
|
||||
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Option<Self>, Self::Rejection> {
|
||||
Ok(parts.extensions.get::<Self>().cloned())
|
||||
}
|
||||
}
|
||||
|
||||
impl<AC: AdditionalClaims> Deref for OidcClaims<AC> {
|
||||
type Target = IdTokenClaims<AC, CoreGenderClaim>;
|
||||
|
||||
|
@ -53,7 +66,6 @@ where
|
|||
#[derive(Clone)]
|
||||
pub struct OidcAccessToken(pub String);
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for OidcAccessToken
|
||||
where
|
||||
S: Send + Sync,
|
||||
|
@ -69,6 +81,17 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> OptionalFromRequestParts<S> for OidcAccessToken
|
||||
where
|
||||
S: Send + Sync,
|
||||
{
|
||||
type Rejection = Infallible;
|
||||
|
||||
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Option<Self>, Self::Rejection> {
|
||||
Ok(parts.extensions.get::<Self>().cloned())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for OidcAccessToken {
|
||||
type Target = str;
|
||||
|
||||
|
@ -147,7 +170,6 @@ impl OidcRpInitiatedLogout {
|
|||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for OidcRpInitiatedLogout
|
||||
where
|
||||
S: Send + Sync,
|
||||
|
@ -159,13 +181,25 @@ where
|
|||
.extensions
|
||||
.get::<Option<Self>>()
|
||||
.cloned()
|
||||
.ok_or(ExtractorError::Unauthorized)?{
|
||||
.ok_or(ExtractorError::Unauthorized)?
|
||||
{
|
||||
Some(this) => Ok(this),
|
||||
None => Err(ExtractorError::RpInitiatedLogoutNotSupported),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> OptionalFromRequestParts<S> for OidcRpInitiatedLogout
|
||||
where
|
||||
S: Send + Sync,
|
||||
{
|
||||
type Rejection = Infallible;
|
||||
|
||||
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Option<Self>, Self::Rejection> {
|
||||
Ok(parts.extensions.get::<Option<Self>>().cloned().flatten())
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoResponse for OidcRpInitiatedLogout {
|
||||
/// redirect to the logout uri and signal the [`crate::middleware::OidcAuthMiddleware`] that
|
||||
/// the session should be cleared
|
||||
|
|
Loading…
Reference in a new issue