Skip to content

Commit

Permalink
Merge pull request #159 from bcgov/yj
Browse files Browse the repository at this point in the history
chore: bceid web service call
  • Loading branch information
ychung-mot authored Apr 17, 2024
2 parents 5c1002f + 95ae712 commit f06a5ad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
7 changes: 1 addition & 6 deletions server/StrDss.Common/CommonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,7 @@ public static bool IsNumericType(this Type type)

public static bool IsIdirUser(this string str)
{
return str.ToUpperInvariant() == BceidUserTypes.Internal;
}

public static bool IsBusinessUser(this string str)
{
return str.ToUpperInvariant() == BceidUserTypes.Business;
return str.ToLowerInvariant() == StrDssIdProviders.Idir;
}
}
}
4 changes: 3 additions & 1 deletion server/StrDss.Service/Bceid/BceidApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private void RefreshCache(object source, ElapsedEventArgs e)
account.UserGuid = userGuid ?? new Guid(response.account.guid.value);
account.UserType = userType;

if (account.UserType.IsBusinessUser())
if (account.UserType == "business")
{
account.BusinessGuid = response.account.business.guid.value == "" ? Guid.Empty : new Guid(response.account.business.guid.value);
account.BusinessLegalName = response.account.business.legalName.value;
Expand All @@ -133,5 +133,7 @@ private void RefreshCache(object source, ElapsedEventArgs e)
return ("", account);
}



}
}
36 changes: 20 additions & 16 deletions server/StrDss.Service/UserService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using StrDss.Common;
using StrDss.Data;
Expand Down Expand Up @@ -30,16 +31,18 @@ public class UserService : ServiceBase, IUserService
private IEmailMessageService _emailService;
private IEmailMessageRepository _emailRepo;
private IBceidApi _bceid;
private IConfiguration _config;

public UserService(ICurrentUser currentUser, IFieldValidatorService validator, IUnitOfWork unitOfWork, IMapper mapper, IHttpContextAccessor httpContextAccessor, ILogger<StrDssLogger> logger,
IUserRepository userRepo, IOrganizationRepository orgRepo, IEmailMessageService emailService, IEmailMessageRepository emailRepo, IBceidApi bceid)
IUserRepository userRepo, IOrganizationRepository orgRepo, IEmailMessageService emailService, IEmailMessageRepository emailRepo, IBceidApi bceid, IConfiguration config)
: base(currentUser, validator, unitOfWork, mapper, httpContextAccessor, logger)
{
_userRepo = userRepo;
_orgRepo = orgRepo;
_emailService = emailService;
_emailRepo = emailRepo;
_bceid = bceid;
_config = config;
}

public async Task<PagedDto<UserListtDto>> GetUserListAsync(string status, string search, long? orgranizationId, int pageSize, int pageNumber, string orderBy, string direction)
Expand All @@ -61,21 +64,22 @@ public async Task<Dictionary<string, List<string>>> CreateAccessRequestAsync(Acc
return errors;
}

//if (_currentUser.IdentityProviderNm == StrDssIdProviders.BceidBusiness)
//{
// var (error, account) = await _bceid.GetBceidAccountCachedAsync(_currentUser.UserGuid, "", StrDssIdProviders.BceidBusiness, _currentUser.UserGuid, _currentUser.IdentityProviderNm);

// if (account == null)
// {
// _logger.LogError($"BCeID call error: {error}");
// }

// if (account != null)
// {
// _currentUser.FirstName = account.FirstName;
// _currentUser.LastName = account.LastName;
// }
//}
if (_currentUser.IdentityProviderNm == StrDssIdProviders.BceidBusiness)
{
var requestorGuid = new Guid(_config.GetValue<string>("SA_USER_GUID")!);
var (error, account) = await _bceid.GetBceidAccountCachedAsync(_currentUser.UserGuid, "", StrDssIdProviders.BceidBusiness, requestorGuid, StrDssIdProviders.Idir);

if (account == null)
{
_logger.LogError($"BCeID call error: {error}");
}

if (account != null)
{
_currentUser.FirstName = account.FirstName;
_currentUser.LastName = account.LastName;
}
}

if (userDto == null)
{
Expand Down

0 comments on commit f06a5ad

Please sign in to comment.