Skip to content

Commit

Permalink
fix overwriting of external claims
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-jmattson committed May 9, 2024
1 parent f7a3629 commit f8c5238
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Identity.Accounts/Services/AccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public async Task<Account> RegisterExternalUser(ClaimsPrincipal principal, strin

UpdateProperty(account, "origin", subClaim.Issuer);

if (_options.Registration.StoreEmail && registration.Username.IsEmailAddress())
if (_options.Registration.StoreEmail && email.IsEmailAddress())
{
UpdateProperty(account, ClaimTypes.Email, registration.Username);
}
Expand All @@ -221,13 +221,13 @@ public async Task<Account> RegisterExternalUser(ClaimsPrincipal principal, strin

private void UpdateExternalUserProfile(Data.Account account, ClaimsPrincipal principal)
{
UpdateProperty(account, ClaimTypes.Name, principal.FindFirst(ClaimTypes.Name)?.Value);
UpdateProperty(account, ClaimTypes.Avatar, principal.FindFirst(ClaimTypes.Avatar)?.Value);
UpdateProperty(account, ClaimTypes.Org, principal.FindFirst(ClaimTypes.Org)?.Value);
UpdateProperty(account, ClaimTypes.IdAffiliate, principal.FindFirst(ClaimTypes.IdAffiliate)?.Value);
UpdateProperty(account, ClaimTypes.Unit, principal.FindFirst(ClaimTypes.Unit)?.Value);
UpdateProperty(account, ClaimTypes.OrgLogo, principal.FindFirst(ClaimTypes.OrgLogo)?.Value);
UpdateProperty(account, ClaimTypes.UnitLogo, principal.FindFirst(ClaimTypes.UnitLogo)?.Value);
UpdatePropertyIfValue(account, ClaimTypes.Name, principal.FindFirst(ClaimTypes.Name)?.Value);
UpdatePropertyIfValue(account, ClaimTypes.Avatar, principal.FindFirst(ClaimTypes.Avatar)?.Value);
UpdatePropertyIfValue(account, ClaimTypes.Org, principal.FindFirst(ClaimTypes.Org)?.Value);
UpdatePropertyIfValue(account, ClaimTypes.IdAffiliate, principal.FindFirst(ClaimTypes.IdAffiliate)?.Value);
UpdatePropertyIfValue(account, ClaimTypes.Unit, principal.FindFirst(ClaimTypes.Unit)?.Value);
UpdatePropertyIfValue(account, ClaimTypes.OrgLogo, principal.FindFirst(ClaimTypes.OrgLogo)?.Value);
UpdatePropertyIfValue(account, ClaimTypes.UnitLogo, principal.FindFirst(ClaimTypes.UnitLogo)?.Value);
}

protected async Task<Data.Account> Register(string accountName, string name, AccountTokenType type, bool id_affiliate, string globalId = "")
Expand Down Expand Up @@ -899,6 +899,12 @@ public async Task RemoveAccountAsync(int accountId, string accountName)
}
}

private void UpdatePropertyIfValue(Data.Account account, string key, string val)
{
if (val.HasValue())
UpdateProperty(account, key, val);
}

private void UpdateProperty(Data.Account account, string key, string val)
{
var prop = account.Properties.SingleOrDefault(p => p.Key == key);
Expand Down

0 comments on commit f8c5238

Please sign in to comment.