Skip to content

Commit

Permalink
fix bceid user name issue (#1668)
Browse files Browse the repository at this point in the history
# Description

This PR includes the following proposed change(s):

- bceid return all name in name claim, we need to parse it to get the
correct fn and ln.
  • Loading branch information
peggy-quartech authored Oct 29, 2024
1 parent cfa8218 commit b56a850
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/Spd.Manager.Licence/BizProfileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ public async Task<BizUserLoginResponse> Handle(BizLoginCommand cmd, Cancellation
//return the loginResponse
//update the biz
await UpdateBiz(cmd, bizInfoFormBceid, ct);
await UpdatePortalUser(cmd.BceidIdentityInfo, portalUser.Id, ct);
BizUserLoginResponse response = _mapper.Map<BizUserLoginResponse>(portalUser);
response.BceidBizTradeName = bizInfoFormBceid?.TradeName;

return response;
}
else
Expand Down Expand Up @@ -239,6 +241,16 @@ private async Task<PortalUserResp> AddPortalUserToBiz(BceidIdentityInfo info, Gu
}, ct);
}

private async Task<PortalUserResp> UpdatePortalUser(BceidIdentityInfo info, Guid portalUserId, CancellationToken ct)
{
return await _portalUserRepository.ManageAsync(new UpdatePortalUserCmd()
{
Id = portalUserId,
FirstName = info.FirstName,
LastName = info.LastName,
}, ct);
}

private async Task ProcessBranchAddresses(List<BranchAddr> branches, List<BranchAddr> branchesToProcess, Guid bizId, CancellationToken ct)
{
// Remove branches defined in the entity that are not part of the request
Expand Down
19 changes: 17 additions & 2 deletions src/Spd.Utilities.LogonUser/IPrincipalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ public static BcscIdentityInfo GetBcscUserIdentityInfo(this IPrincipal principal
public static BceidIdentityInfo GetBceidUserIdentityInfo(this IPrincipal principal)
{
var claim = ValidatePrincipal(principal);

return new BceidIdentityInfo()
{
DisplayName = claim.GetClaimValue<string>("display_name"),
Email = claim.GetClaimValue<string>(BCeID_Email),
FirstName = claim.GetClaimValue<string>(BCeID_GIVEN_NAME),
LastName = claim.GetClaimValue<string>(BCeID_SUR_NAME),
FirstName = GetBceidUserFirstName(claim.GetClaimValue<string>("name")),
LastName = GetBceidUserLastName(claim.GetClaimValue<string>("name")),
PreferredUserName = claim.GetClaimValue<string>("preferred_username"),
BCeIDUserName = claim.GetClaimValue<string>("bceid_username"),
UserGuid = claim.GetClaimValue<Guid?>("bceid_user_guid"),
Expand Down Expand Up @@ -151,5 +152,19 @@ public static (string?, string?) GetMiddleNames(string? gns, string? fn)
}
return (null, null);
}

private static string? GetBceidUserFirstName(string? name)
{
if (name == null) return null;
string[] n = name.Split(' ');
return n[0].Trim();
}

private static string? GetBceidUserLastName(string? name)
{
if (name == null) return null;
string[] n = name.Split(' ');
return name.Substring(n[0].Length).Trim();
}
}
}

0 comments on commit b56a850

Please sign in to comment.