Skip to content

Commit 376ef3c

Browse files
authored
Merge pull request #668 from bcgov/2.0.6
2.0.6
2 parents c2f756a + 6f943d7 commit 376ef3c

28 files changed

+101
-52
lines changed

api/Hmcr.Api/Authentication/HmcrJwtBearerEvents.cs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,33 @@ private async Task<bool> PopulateCurrentUserFromDb(ClaimsPrincipal principal)
7070
{
7171
var isApiClient = false;
7272
bool.TryParse(principal.FindFirstValue(HmcrClaimTypes.KcIsApiClient), out isApiClient);
73+
isApiClient = true;
7374

74-
//preferred_username token has a form of "{username}@{directory}".
75-
var preferredUsername = isApiClient ? principal.FindFirstValue(HmcrClaimTypes.KcApiUsername) : principal.FindFirstValue(HmcrClaimTypes.KcUsername);
76-
var usernames = preferredUsername.Split("@");
77-
var username = usernames[0].ToUpperInvariant();
78-
var directory = usernames[1].ToUpperInvariant();
75+
//preferred_username token has a form of "{guid}@{directory}".
76+
//var preferredUsername = isApiClient ? principal.FindFirstValue(HmcrClaimTypes.KcApiUsername) : principal.FindFirstValue(HmcrClaimTypes.KcUsername);
77+
var preferredUsername = principal.FindFirstValue(HmcrClaimTypes.KcUsername);
78+
var username = principal.FindFirstValue(HmcrClaimTypes.KcApiUsername);
7979

80-
var userGuidClaim = directory.ToUpperInvariant() == UserTypeDto.IDIR ? HmcrClaimTypes.KcIdirGuid : HmcrClaimTypes.KcBceidGuid;
81-
var userGuid = new Guid(principal.FindFirstValue(userGuidClaim));
82-
var email = principal.FindFirstValue(ClaimTypes.Email).ToUpperInvariant();
80+
var directory = "";
81+
Guid userGuid = new Guid("00000000-0000-0000-0000-000000000000");
82+
var email = "";
83+
if (preferredUsername.Contains("@"))
84+
{
85+
directory = preferredUsername.Split("@")[1].ToUpperInvariant();
86+
username = principal.FindFirstValue(HmcrClaimTypes.KcUsername).Split("@")[0].ToUpperInvariant();
87+
userGuid = new Guid(Guid.Parse(username).ToString());
88+
email = principal.FindFirstValue(ClaimTypes.Email)?.ToUpperInvariant();
89+
90+
}
91+
else
92+
{
93+
94+
username = principal.FindFirstValue(HmcrClaimTypes.KcUsername).Split("@")[0].ToUpperInvariant();
95+
userGuid = new Guid(principal.FindFirstValue("idir_userid")?.ToUpperInvariant());
96+
email = principal.FindFirstValue(ClaimTypes.Email)?.ToUpperInvariant();
97+
98+
}
99+
83100

84101
var user = await _userService.GetActiveUserEntityAsync(userGuid);
85102
if (user == null)
@@ -96,7 +113,7 @@ private async Task<bool> PopulateCurrentUserFromDb(ClaimsPrincipal principal)
96113
email = user.Email;
97114
}
98115

99-
if (directory == "IDIR")
116+
if (directory.Equals("IDIR", StringComparison.OrdinalIgnoreCase))
100117
{
101118
_curentUser.UserGuid = userGuid;
102119
_curentUser.UserType = UserTypeDto.INTERNAL;
@@ -105,8 +122,8 @@ private async Task<bool> PopulateCurrentUserFromDb(ClaimsPrincipal principal)
105122
{
106123
_curentUser.UserGuid = userGuid;
107124
_curentUser.BusinessGuid = user.BusinessGuid;
108-
_curentUser.BusinessLegalName = user.Party.BusinessLegalName;
109-
_curentUser.BusinessNumber = user.Party.BusinessNumber ?? 0;
125+
_curentUser.BusinessLegalName = user.Party?.BusinessLegalName;
126+
_curentUser.BusinessNumber = user.Party?.BusinessNumber ?? 0;
110127
_curentUser.UserType = UserTypeDto.BUSINESS;
111128
}
112129

api/Hmcr.Api/Startup.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.Extensions.Configuration;
1111
using Microsoft.Extensions.DependencyInjection;
1212
using Microsoft.Extensions.Hosting;
13+
using Microsoft.IdentityModel.Logging;
1314
using Serilog.Ui.PostgreSqlProvider.Extensions;
1415
using Serilog.Ui.Web;
1516

@@ -29,6 +30,7 @@ public Startup(IConfiguration configuration, IWebHostEnvironment env)
2930

3031
public void ConfigureServices(IServiceCollection services)
3132
{
33+
IdentityModelEventSource.ShowPII = true;
3234
var connectionString = Configuration.GetValue<string>("ConnectionStrings:HMCR");
3335
var enableSensitiveDataLogging = Configuration.GetValue<bool>("EnableSensitiveDataLogging");
3436

api/Hmcr.Api/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"AllowedHosts": "*",
33
"Constants": {
4-
"Version": "2.0.5.0",
4+
"Version": "2.0.6.0",
55
"SwaggerApiUrl": "/swagger/v1/swagger.json"
66
},
77
"Serilog": {
@@ -93,7 +93,7 @@
9393
"InventoryAPI": 120
9494
},
9595
"JWT": {
96-
"Authority": "https://dev.oidc.gov.bc.ca/auth/realms/<realmid>",
96+
"Authority": "https://dev.loginproxy.gov.bc.ca/auth/realms/<realmid>",
9797
"Audience": "<app-id>"
9898
},
9999
"BCeID": {

api/Hmcr.Bceid/BceidApi.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ private void RefreshCache(object source, ElapsedEventArgs e)
9595
}
9696

9797
request.onlineServiceId = _client.Osid;
98-
9998
var response = await _client.getAccountDetailAsync(request);
10099

101100
if (response.code != ResponseCode.Success)

api/Hmcr.Data/Database/Entities/AppDbContextPartial.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Hmcr.Model;
22
using Hmcr.Model.Dtos;
3+
using Hmcr.Model.Dtos.User;
4+
using Hmcr.Model.Utils;
35
using Microsoft.EntityFrameworkCore;
46
using Microsoft.EntityFrameworkCore.ChangeTracking;
57
using System;
@@ -66,14 +68,14 @@ private void PerformAudit()
6668
if (entry.Members.Any(m => m.Metadata.Name == AppCreateUserGuid)) //auditable entity
6769
{
6870
entry.Member(AppLastUpdateUserid).CurrentValue = _currentUser.Username;
69-
entry.Member(AppLastUpdateUserDirectory).CurrentValue = _currentUser.AuthDirName;
71+
entry.Member(AppLastUpdateUserDirectory).CurrentValue = _currentUser.AuthDirName.ToShortDirectory();
7072
entry.Member(AppLastUpdateUserGuid).CurrentValue = _currentUser.UserGuid;
7173
entry.Member(AppLastUpdateTimestamp).CurrentValue = currentTime;
7274

7375
if (entry.State == EntityState.Added)
7476
{
7577
entry.Member(AppCreateUserid).CurrentValue = _currentUser.Username;
76-
entry.Member(AppCreateUserDirectory).CurrentValue = _currentUser.AuthDirName;
78+
entry.Member(AppCreateUserDirectory).CurrentValue = _currentUser.AuthDirName.ToShortDirectory();
7779
entry.Member(AppCreateUserGuid).CurrentValue = _currentUser.UserGuid;
7880
entry.Member(AppCreateTimestamp).CurrentValue = currentTime;
7981
entry.Member(ConcurrencyControlNumber).CurrentValue = (long)1;

api/Hmcr.Model/HmcrClaimTypes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ public static class HmcrClaimTypes
44
{
55
public const string KcUsername = "preferred_username";
66
public const string KcBceidGuid = "bceid_userid";
7-
public const string KcIdirGuid = "idir_userid";
7+
public const string KcIdirGuid = "idir_user_guid";
88
public const string KcIsApiClient = "api_client";
9-
public const string KcApiUsername = "username";
9+
public const string KcApiUsername = "idir_username";
1010

1111
public const string Permission = "HMCR_PERMISSION";
1212
public const string ServiceAreaNumber = "HMCR_SERVICE_AREA_NUMBER";

api/Hmcr.Model/Utils/StringExtensions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,20 @@ public static bool IsBusinessUser(this string str)
109109
return str.ToUpperInvariant() == UserTypeDto.BUSINESS;
110110
}
111111

112+
public static string ToShortDirectory(this string str)
113+
{
114+
var directoryStr = str.Trim().ToUpperInvariant();
115+
switch (directoryStr)
116+
{
117+
case "BCEIDBUSINESS":
118+
return UserTypeDto.BCeId;
119+
case "IDIR":
120+
return UserTypeDto.IDIR;
121+
default:
122+
return directoryStr.Substring(0, 12);
123+
}
124+
}
125+
112126
public static string GetSha256Hash(this string text)
113127
{
114128
if (string.IsNullOrEmpty(text))

client/.env.development

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
BROWSER=none
22
REACT_APP_API_HOST=localhost:27238
33
REACT_APP_CLIENT_ORIGIN=localhost:3000
4-
REACT_APP_SSO_CLIENT=hmcr-public-dev
5-
REACT_APP_SSO_REALM=fygf50pt
6-
REACT_APP_SSO_HOST=https://dev.oidc.gov.bc.ca/auth
4+
REACT_APP_SSO_CLIENT=<clientid>
5+
REACT_APP_SSO_REALM=<realms>
6+
REACT_APP_SSO_HOST=<sso_host>
77
REACT_APP_DEFAULT_PAGE_SIZE_OPTIONS=25,50,100,200
88
REACT_APP_DEFAULT_PAGE_SIZE=25

client/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ This section has moved here: https://facebook.github.io/create-react-app/docs/de
6666
### `npm run build` fails to minify
6767

6868
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
69+

client/package-lock.json

Lines changed: 31 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)