Content-Length: 282946 | pFad | https://github.com/sebadob/rauthy/commit/29dbe26a5c8f76d9a61931078811192ac2fb782d

52 Merge pull request #264 from sebadob/fix-access_token-sub-claim · sebadob/rauthy@29dbe26 · GitHub
Skip to content

Commit

Permalink
Merge pull request #264 from sebadob/fix-access_token-sub-claim
Browse files Browse the repository at this point in the history
Fix access token sub claim
  • Loading branch information
sebadob authored Feb 9, 2024
2 parents 963644c + 6bb6ec1 commit 29dbe26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
3 changes: 2 additions & 1 deletion rauthy-models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ pub struct JwtAccessClaims {
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_origens: Option<Vec<String>>,
// user part
pub uid: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub preferred_username: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
25 changes: 12 additions & 13 deletions rauthy-service/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,18 +381,12 @@ pub async fn build_access_token(
scope: Option<String>,
scope_customs: Option<(Vec<&Scope>, &Option<HashMap<String, Vec<u8>>>)>,
) -> Result<String, ErrorResponse> {
let scope = if let Some(s) = scope {
s
} else {
client.default_scopes.clone().replace(',', " ")
};

let mut custom_claims = JwtAccessClaims {
typ: JwtTokenType::Bearer,
azp: client.id.to_string(),
scope,
scope: scope.unwrap_or_else(|| client.default_scopes.clone().replace(',', " ")),
allowed_origens: None,
uid: None,
email: None,
preferred_username: None,
roles: None,
groups: None,
Expand All @@ -401,17 +395,22 @@ pub async fn build_access_token(
};

// add user specific claims if available
let mut sub = None;
if let Some(user) = user {
sub = Some(user.email.clone());
let sub = if let Some(user) = user {
custom_claims.preferred_username = Some(user.email.clone());
custom_claims.uid = Some(user.id.clone());
custom_claims.roles = Some(user.get_roles());

if custom_claims.scope.contains("email") {
custom_claims.email = Some(user.email.clone());
}

if custom_claims.scope.contains("groups") {
custom_claims.groups = Some(user.get_groups());
}
}

Some(&user.id)
} else {
None
};

if let Some((cust, user_attrs)) = scope_customs {
let user_attrs = user_attrs.as_ref().unwrap();
Expand Down

0 comments on commit 29dbe26

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/sebadob/rauthy/commit/29dbe26a5c8f76d9a61931078811192ac2fb782d

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy