From 914f5941bffe2545a37f1d57037e8466e9d808e3 Mon Sep 17 00:00:00 2001 From: ychung-mot Date: Mon, 16 Sep 2024 06:59:55 -0700 Subject: [PATCH] chore: create aps user returns id --- gateway/strdata.yaml | 55 +++++++++++++++++++ .../StrDss.Api/Controllers/UsersController.cs | 4 +- .../Repositories/UserRepository.cs | 6 +- server/StrDss.Service/UserService.cs | 10 ++-- 4 files changed, 66 insertions(+), 9 deletions(-) diff --git a/gateway/strdata.yaml b/gateway/strdata.yaml index fa140ce8..ca093e93 100644 --- a/gateway/strdata.yaml +++ b/gateway/strdata.yaml @@ -109,6 +109,61 @@ services: config: header: GW-JWT include_credential_type: false +- name: strdata-uat + host: uat.strdata.gov.bc.ca + tags: [ns.strdata] + port: 443 + protocol: https + retries: 0 + routes: + - name: strdata-uat + tags: [ns.strdata] + hosts: + - strdata-uat.api.gov.bc.ca + methods: + - GET + paths: [/api/organizations/strrequirements] + strip_path: false + https_redirect_status_code: 426 + path_handling: v0 + request_buffering: true + response_buffering: true + plugins: + - name: jwt-keycloak + tags: [ns.strdata] + enabled: true + config: + allowed_iss: [https://test.loginproxy.gov.bc.ca/auth/realms/apigw] + allowed_aud: gateway-strdata + run_on_preflight: true + iss_key_grace_period: 10 + maximum_expiration: 0 + algorithm: RS256 + claims_to_verify: + - exp + uri_param_names: + - jwt + cookie_names: [] + scope: + roles: + realm_roles: + client_roles: + anonymous: + consumer_match: true + consumer_match_claim: azp + consumer_match_claim_custom_id: true + consumer_match_ignore_not_found: false + - name: request-transformer + tags: [ns.strdata] + enabled: true + config: + http_method: + - name: kong-upstream-jwt + enabled: true + tags: [ns.strdata] + config: + header: GW-JWT + include_credential_type: false - name: strdata-prod host: strdata.gov.bc.ca tags: [ns.strdata] diff --git a/server/StrDss.Api/Controllers/UsersController.cs b/server/StrDss.Api/Controllers/UsersController.cs index 4353a528..a2e0c7c5 100644 --- a/server/StrDss.Api/Controllers/UsersController.cs +++ b/server/StrDss.Api/Controllers/UsersController.cs @@ -155,14 +155,14 @@ public async Task GetBceidUserInfo() [HttpPost("aps", Name = "CreateApsUser")] public async Task CreateApsUser(ApsUserCreateDto dto) { - var errors = await _userService.CreateApsUserAsync(dto); + var (errors, userId) = await _userService.CreateApsUserAsync(dto); if (errors.Count > 0) { return ValidationUtils.GetValidationErrorResult(errors, ControllerContext); } - return Ok(); + return Ok(userId); } } } diff --git a/server/StrDss.Data/Repositories/UserRepository.cs b/server/StrDss.Data/Repositories/UserRepository.cs index 611cdf5f..6a4afd9e 100644 --- a/server/StrDss.Data/Repositories/UserRepository.cs +++ b/server/StrDss.Data/Repositories/UserRepository.cs @@ -25,7 +25,7 @@ public interface IUserRepository Task> GetAccessRequestStatuses(); Task AcceptTermsConditions(); Task UpdateUserNamesAsync(long userId, string firstName, string lastName); - Task CreateApsUserAsync(ApsUserCreateDto dto); + Task CreateApsUserAsync(ApsUserCreateDto dto); Task ApsUserExists(string clientId); } public class UserRepository : RepositoryBase, IUserRepository @@ -235,7 +235,7 @@ public async Task UpdateUserNamesAsync(long userId, string firstName, string las entity.GivenNm = firstName; } - public async Task CreateApsUserAsync(ApsUserCreateDto dto) + public async Task CreateApsUserAsync(ApsUserCreateDto dto) { dto.FamilyNm = dto.DisplayNm; @@ -252,6 +252,8 @@ public async Task CreateApsUserAsync(ApsUserCreateDto dto) } await _dbContext.AddAsync(userEntity); + + return userEntity; } public async Task ApsUserExists(string clientId) diff --git a/server/StrDss.Service/UserService.cs b/server/StrDss.Service/UserService.cs index 6c96ec22..8ed4308d 100644 --- a/server/StrDss.Service/UserService.cs +++ b/server/StrDss.Service/UserService.cs @@ -27,7 +27,7 @@ public interface IUserService Task GetUserByIdAsync(long userId); Task>> UpdateUserAsync(UserUpdateDto dto); Task GetBceidUserInfo(); - Task>> CreateApsUserAsync(ApsUserCreateDto dto); + Task<(Dictionary>, long)> CreateApsUserAsync(ApsUserCreateDto dto); Task<(UserDto? user, List permissions)> GetUserByDisplayNameAsync(string displayName); } public class UserService : ServiceBase, IUserService @@ -529,7 +529,7 @@ private async Task ValidateOrgAndRoles(IOrgRoles dto, Dictionary>> CreateApsUserAsync(ApsUserCreateDto dto) + public async Task<(Dictionary>, long)> CreateApsUserAsync(ApsUserCreateDto dto) { var errors = new Dictionary>(); @@ -545,13 +545,13 @@ public async Task>> CreateApsUserAsync(ApsUserCr errors.AddItem("client_id", $"The client ID {dto.DisplayNm} already exists."); } - if (errors.Any()) return errors; + if (errors.Any()) return (errors, 0); - await _userRepo.CreateApsUserAsync(dto); + var entity = await _userRepo.CreateApsUserAsync(dto); _unitOfWork.Commit(); - return errors; + return (errors, entity.UserIdentityId); } } }