use std::borrow::Cow;
use crate::webserver::http_request_info::RequestInfo;
pub(super) async fn user_info<'a>(
request: &'a RequestInfo,
claim: Cow<'a, str>,
) -> anyhow::Result<Option<String>> {
let Some(claims) = &request.oidc_claims else {
return Ok(None);
};
let claim_value_str = match claim.as_ref() {
"iss" => Some(claims.issuer().to_string()),
"exp" => Some(claims.expiration().timestamp().to_string()),
"iat" => Some(claims.issue_time().timestamp().to_string()),
"sub" => Some(claims.subject().to_string()),
"auth_time" => claims.auth_time().map(|t| t.timestamp().to_string()),
"nonce" => claims.nonce().map(|n| n.secret().clone()), "acr" => claims.auth_context_ref().map(|acr| acr.to_string()),
"azp" => claims.authorized_party().map(|azp| azp.to_string()),
"at_hash" => claims.access_token_hash().map(|h| h.to_string()),
"c_hash" => claims.code_hash().map(|h| h.to_string()),
"name" => claims
.name()
.and_then(|n| n.get(None))
.map(|s| s.to_string()),
"given_name" => claims
.given_name()
.and_then(|n| n.get(None))
.map(|s| s.to_string()),
"family_name" => claims
.family_name()
.and_then(|n| n.get(None))
.map(|s| s.to_string()),
"middle_name" => claims
.middle_name()
.and_then(|n| n.get(None))
.map(|s| s.to_string()),
"nickname" => claims
.nickname()
.and_then(|n| n.get(None))
.map(|s| s.to_string()),
"preferred_username" => claims.preferred_username().map(|u| u.to_string()),
"profile" => claims
.profile()
.and_then(|n| n.get(None))
.map(|url_claim| url_claim.as_str().to_string()),
"picture" => claims
.picture()
.and_then(|n| n.get(None))
.map(|url_claim| url_claim.as_str().to_string()),
"website" => claims
.website()
.and_then(|n| n.get(None))
.map(|url_claim| url_claim.as_str().to_string()),
"gender" => claims.gender().map(|g| g.to_string()), "birthdate" => claims.birthdate().map(|b| b.to_string()), "zoneinfo" => claims.zoneinfo().map(|z| z.to_string()), "locale" => claims.locale().map(std::string::ToString::to_string), "updated_at" => claims.updated_at().map(|t| t.timestamp().to_string()),
"email" => claims.email().map(|e| e.to_string()),
"email_verified" => claims.email_verified().map(|b| b.to_string()),
"phone_number" => claims.phone_number().map(|p| p.to_string()),
"phone_number_verified" => claims.phone_number_verified().map(|b| b.to_string()),
additional_claim => claims
.additional_claims()
.0
.get(additional_claim)
.map(std::string::ToString::to_string),
};
Ok(claim_value_str)
}