diff --git a/server/StrDss.Common/CommonExtensions.cs b/server/StrDss.Common/CommonExtensions.cs index 425b110c..884c2e57 100644 --- a/server/StrDss.Common/CommonExtensions.cs +++ b/server/StrDss.Common/CommonExtensions.cs @@ -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; } } } diff --git a/server/StrDss.Service/Bceid/BceidApi.cs b/server/StrDss.Service/Bceid/BceidApi.cs index 1226d237..39b27d4c 100644 --- a/server/StrDss.Service/Bceid/BceidApi.cs +++ b/server/StrDss.Service/Bceid/BceidApi.cs @@ -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; @@ -133,5 +133,7 @@ private void RefreshCache(object source, ElapsedEventArgs e) return ("", account); } + + } } diff --git a/server/StrDss.Service/UserService.cs b/server/StrDss.Service/UserService.cs index 137026ce..f72aea0e 100644 --- a/server/StrDss.Service/UserService.cs +++ b/server/StrDss.Service/UserService.cs @@ -1,5 +1,6 @@ using AutoMapper; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using StrDss.Common; using StrDss.Data; @@ -30,9 +31,10 @@ 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 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; @@ -40,6 +42,7 @@ public UserService(ICurrentUser currentUser, IFieldValidatorService validator, I _emailService = emailService; _emailRepo = emailRepo; _bceid = bceid; + _config = config; } public async Task> GetUserListAsync(string status, string search, long? orgranizationId, int pageSize, int pageNumber, string orderBy, string direction) @@ -61,21 +64,22 @@ public async Task>> 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("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) {