From 024d9380c9e4636ab8e3c877559145bd86fde5b0 Mon Sep 17 00:00:00 2001 From: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com> Date: Wed, 15 Sep 2021 12:27:27 -0500 Subject: [PATCH] [SSO Auto Enroll] Auto Enroll status retrieval (#1540) * [SSO Auto Enroll] Auto Enroll status retrieval * Updated object property to match server --- .../Accounts/SetPasswordPageViewModel.cs | 21 +++++++++++++------ src/Core/Abstractions/IApiService.cs | 1 + .../OrganizationAutoEnrollStatusResponse.cs | 8 +++++++ src/Core/Services/ApiService.cs | 6 ++++++ 4 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 src/Core/Models/Response/OrganizationAutoEnrollStatusResponse.cs diff --git a/src/App/Pages/Accounts/SetPasswordPageViewModel.cs b/src/App/Pages/Accounts/SetPasswordPageViewModel.cs index 60f53a2c6..6f1f4f47e 100644 --- a/src/App/Pages/Accounts/SetPasswordPageViewModel.cs +++ b/src/App/Pages/Accounts/SetPasswordPageViewModel.cs @@ -97,12 +97,21 @@ namespace Bit.App.Pages public async Task InitAsync() { await CheckPasswordPolicy(); - - var org = await _userService.GetOrganizationByIdentifierAsync(OrgIdentifier); - OrgId = org?.Id; - var policyList = await _policyService.GetAll(PolicyType.ResetPassword); - var policyResult = _policyService.GetResetPasswordPolicyOptions(policyList, OrgId); - ResetPasswordAutoEnroll = policyResult.Item2 && policyResult.Item1.AutoEnrollEnabled; + + try + { + var response = await _apiService.GetOrganizationAutoEnrollStatusAsync(OrgIdentifier); + OrgId = response.Id; + ResetPasswordAutoEnroll = response.ResetPasswordEnrolled; + } + catch (ApiException e) + { + if (e?.Error != null) + { + await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(), + AppResources.AnErrorHasOccurred); + } + } } public async Task SubmitAsync() diff --git a/src/Core/Abstractions/IApiService.cs b/src/Core/Abstractions/IApiService.cs index 8a29eb535..dc09b2d6b 100644 --- a/src/Core/Abstractions/IApiService.cs +++ b/src/Core/Abstractions/IApiService.cs @@ -59,6 +59,7 @@ namespace Bit.Core.Abstractions Task PutDeviceTokenAsync(string identifier, DeviceTokenRequest request); Task PostEventsCollectAsync(IEnumerable request); Task GetOrganizationKeysAsync(string id); + Task GetOrganizationAutoEnrollStatusAsync(string identifier); Task PutOrganizationUserResetPasswordEnrollmentAsync(string orgId, string userId, OrganizationUserResetPasswordEnrollmentRequest request); diff --git a/src/Core/Models/Response/OrganizationAutoEnrollStatusResponse.cs b/src/Core/Models/Response/OrganizationAutoEnrollStatusResponse.cs new file mode 100644 index 000000000..7f5e4a013 --- /dev/null +++ b/src/Core/Models/Response/OrganizationAutoEnrollStatusResponse.cs @@ -0,0 +1,8 @@ +namespace Bit.Core.Models.Response +{ + public class OrganizationAutoEnrollStatusResponse + { + public string Id { get; set; } + public bool ResetPasswordEnrolled { get; set; } + } +} diff --git a/src/Core/Services/ApiService.cs b/src/Core/Services/ApiService.cs index e0a6fa6ae..6f24c52ca 100644 --- a/src/Core/Services/ApiService.cs +++ b/src/Core/Services/ApiService.cs @@ -410,6 +410,12 @@ namespace Bit.Core.Services { return SendAsync(HttpMethod.Get, $"/organizations/{id}/keys", null, true, true); } + + public Task GetOrganizationAutoEnrollStatusAsync(string identifier) + { + return SendAsync(HttpMethod.Get, + $"/organizations/{identifier}/auto-enroll-status", null, true, true); + } #endregion