use std::ops::Deref; use crate::{error::ExtractorError, AdditionalClaims}; use async_trait::async_trait; use axum_core::extract::FromRequestParts; use http::request::Parts; use openidconnect::{core::CoreGenderClaim, IdTokenClaims}; /// Extractor for the OpenID Connect Claims. /// /// This Extractor will only return the Claims when the cached session is valid and [crate::middleware::OidcAuthMiddleware] is loaded. #[derive(Clone)] pub struct OidcClaims(pub IdTokenClaims); #[async_trait] impl FromRequestParts for OidcClaims where S: Send + Sync, AC: AdditionalClaims, { type Rejection = ExtractorError; async fn from_request_parts(parts: &mut Parts, _: &S) -> Result { parts .extensions .get::() .cloned() .ok_or(ExtractorError::Unauthorized) } } impl Deref for OidcClaims { type Target = IdTokenClaims; fn deref(&self) -> &Self::Target { &self.0 } } impl AsRef> for OidcClaims where AC: AdditionalClaims, { fn as_ref(&self) -> &IdTokenClaims { &self.0 } } /// Extractor for the OpenID Connect Access Token. /// /// This Extractor will only return the Access Token when the cached session is valid and [crate::middleware::OidcAuthMiddleware] is loaded. #[derive(Clone)] pub struct OidcAccessToken(pub String); #[async_trait] impl FromRequestParts for OidcAccessToken where S: Send + Sync, { type Rejection = ExtractorError; async fn from_request_parts(parts: &mut Parts, _: &S) -> Result { parts .extensions .get::() .cloned() .ok_or(ExtractorError::Unauthorized) } } impl Deref for OidcAccessToken { type Target = str; fn deref(&self) -> &Self::Target { &self.0 } } impl AsRef for OidcAccessToken { fn as_ref(&self) -> &str { self.0.as_str() } }