Display some more OIDC information

This commit is contained in:
Simon Goller 2024-06-05 16:36:31 +02:00
parent 1565fc0017
commit 9888ac4062

View file

@ -191,12 +191,27 @@ pub async fn login() -> Redirect {
#[cfg(feature = "oidc")] #[cfg(feature = "oidc")]
pub async fn auth_info(claims: Option<OidcClaims<EmptyAdditionalClaims>>) -> Response { pub async fn auth_info(claims: Option<OidcClaims<EmptyAdditionalClaims>>) -> Response {
if let Some(oidc_claims) = claims { if let Some(oidc_claims) = claims {
let nickname = oidc_claims let username = oidc_claims
.nickname() .preferred_username()
.map(|s| s.iter().next().map(|s| s.1.as_str().to_string())) .map(|s| s.as_str().to_string())
.unwrap_or_else(|| Some("NickNotSet".to_string())) .unwrap_or_else(|| "NoUsername".to_string());
.unwrap_or_else(|| "NickEmpty".to_string()); let email = oidc_claims
let body = format!("Hello, {}! ", nickname); .email()
.map(|s| s.as_str().to_string())
.unwrap_or_else(|| "MailNotSet".to_string());
let name = oidc_claims
.name()
.map(|s| {
s.iter()
.next()
.map(|s| s.1.as_str().to_string())
.unwrap_or_else(|| "NoLocalizedName".to_string())
})
.unwrap_or_else(|| "NameNotSet".to_string());
let body = format!(
"Hello, {}! Your email is {} and your username is {}",
name, email, username
);
Response::builder() Response::builder()
.status(200) .status(200)
.body(Body::new(body)) .body(Body::new(body))