Browse Source

[PM-1029] Fix Async suffix in ApiService. Add UserKeyNullExceptions.

github-services/pull/2706/head
André Bispo 2 years ago
parent
commit
70a177b4b7
No known key found for this signature in database
GPG Key ID: E5610EF043C76548
  1. 2
      src/App/Pages/Accounts/LoginSsoPageViewModel.cs
  2. 2
      src/App/Pages/Accounts/RemoveMasterPasswordPageViewModel.cs
  3. 10
      src/Core/Abstractions/IApiService.cs
  4. 10
      src/Core/Services/ApiService.cs
  5. 2
      src/Core/Services/CipherService.cs
  6. 3
      src/Core/Services/FolderService.cs
  7. 8
      src/Core/Services/KeyConnectorService.cs

2
src/App/Pages/Accounts/LoginSsoPageViewModel.cs

@ -114,7 +114,7 @@ namespace Bit.App.Pages @@ -114,7 +114,7 @@ namespace Bit.App.Pages
await _deviceActionService.ShowLoadingAsync(AppResources.LoggingIn);
var response = await _apiService.PreValidateSso(OrgIdentifier);
var response = await _apiService.PreValidateSsoAsync(OrgIdentifier);
if (string.IsNullOrWhiteSpace(response?.Token))
{

2
src/App/Pages/Accounts/RemoveMasterPasswordPageViewModel.cs

@ -47,7 +47,7 @@ namespace Bit.App.Pages @@ -47,7 +47,7 @@ namespace Bit.App.Pages
{
await _deviceActionService.ShowLoadingAsync(AppResources.Loading);
await _apiService.PostLeaveOrganization(Organization.Id);
await _apiService.PostLeaveOrganizationAsync(Organization.Id);
await _syncService.FullSyncAsync(true);
await _deviceActionService.HideLoadingAsync();

10
src/Core/Abstractions/IApiService.cs

@ -47,7 +47,7 @@ namespace Bit.Core.Abstractions @@ -47,7 +47,7 @@ namespace Bit.Core.Abstractions
Task PutDeleteCipherAsync(string id);
Task<CipherResponse> PutRestoreCipherAsync(string id);
Task RefreshIdentityTokenAsync();
Task<SsoPrevalidateResponse> PreValidateSso(string identifier);
Task<SsoPrevalidateResponse> PreValidateSsoAsync(string identifier);
Task<TResponse> SendAsync<TRequest, TResponse>(HttpMethod method, string path,
TRequest body, bool authed, bool hasResponse, Action<HttpRequestMessage> alterRequest, bool logoutOnUnauthorized = true);
Task<HttpResponseMessage> SendAsync(HttpRequestMessage requestMessage, CancellationToken cancellationToken = default);
@ -72,10 +72,10 @@ namespace Bit.Core.Abstractions @@ -72,10 +72,10 @@ namespace Bit.Core.Abstractions
Task PutOrganizationUserResetPasswordEnrollmentAsync(string orgId, string userId,
OrganizationUserResetPasswordEnrollmentRequest request);
Task<KeyConnectorUserKeyResponse> GetMasterKeyFromKeyConnectorAsync(string keyConnectorUrl);
Task PostMasterKeyToKeyConnector(string keyConnectorUrl, KeyConnectorUserKeyRequest request);
Task PostSetKeyConnectorKey(SetKeyConnectorKeyRequest request);
Task PostConvertToKeyConnector();
Task PostLeaveOrganization(string id);
Task PostMasterKeyToKeyConnectorAsync(string keyConnectorUrl, KeyConnectorUserKeyRequest request);
Task PostSetKeyConnectorKeyAsync(SetKeyConnectorKeyRequest request);
Task PostConvertToKeyConnectorAsync();
Task PostLeaveOrganizationAsync(string id);
Task<SendResponse> GetSendAsync(string id);
Task<SendResponse> PostSendAsync(SendRequest request);

10
src/Core/Services/ApiService.cs

@ -211,12 +211,12 @@ namespace Bit.Core.Services @@ -211,12 +211,12 @@ namespace Bit.Core.Services
return SendAsync<DeleteAccountRequest, object>(HttpMethod.Delete, "/accounts", request, true, false);
}
public Task PostConvertToKeyConnector()
public Task PostConvertToKeyConnectorAsync()
{
return SendAsync<object, object>(HttpMethod.Post, "/accounts/convert-to-key-connector", null, true, false);
}
public Task PostSetKeyConnectorKey(SetKeyConnectorKeyRequest request)
public Task PostSetKeyConnectorKeyAsync(SetKeyConnectorKeyRequest request)
{
return SendAsync<SetKeyConnectorKeyRequest>(HttpMethod.Post, "/accounts/set-key-connector-key", request, true);
}
@ -486,7 +486,7 @@ namespace Bit.Core.Services @@ -486,7 +486,7 @@ namespace Bit.Core.Services
$"/organizations/{identifier}/auto-enroll-status", null, true, true);
}
public Task PostLeaveOrganization(string id)
public Task PostLeaveOrganizationAsync(string id)
{
return SendAsync<object, object>(HttpMethod.Post, $"/organizations/{id}/leave", null, true, false);
}
@ -541,7 +541,7 @@ namespace Bit.Core.Services @@ -541,7 +541,7 @@ namespace Bit.Core.Services
}
}
public async Task PostMasterKeyToKeyConnector(string keyConnectorUrl, KeyConnectorUserKeyRequest request)
public async Task PostMasterKeyToKeyConnectorAsync(string keyConnectorUrl, KeyConnectorUserKeyRequest request)
{
using (var requestMessage = new HttpRequestMessage())
{
@ -627,7 +627,7 @@ namespace Bit.Core.Services @@ -627,7 +627,7 @@ namespace Bit.Core.Services
return accessToken;
}
public async Task<SsoPrevalidateResponse> PreValidateSso(string identifier)
public async Task<SsoPrevalidateResponse> PreValidateSsoAsync(string identifier)
{
var path = "/account/prevalidate?domainHint=" + WebUtility.UrlEncode(identifier);
using (var requestMessage = new HttpRequestMessage())

2
src/Core/Services/CipherService.cs

@ -252,7 +252,7 @@ namespace Bit.Core.Services @@ -252,7 +252,7 @@ namespace Bit.Core.Services
{
if (!await _cryptoService.HasUserKeyAsync())
{
throw new Exception("No key.");
throw new UserKeyNullException();
}
var decCiphers = new List<CipherView>();
async Task decryptAndAddCipherAsync(Cipher cipher)

3
src/Core/Services/FolderService.cs

@ -4,6 +4,7 @@ using System.Linq; @@ -4,6 +4,7 @@ using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Bit.Core.Abstractions;
using Bit.Core.Exceptions;
using Bit.Core.Models.Data;
using Bit.Core.Models.Domain;
using Bit.Core.Models.Request;
@ -80,7 +81,7 @@ namespace Bit.Core.Services @@ -80,7 +81,7 @@ namespace Bit.Core.Services
var hasKey = await _cryptoService.HasUserKeyAsync();
if (!hasKey)
{
throw new Exception("No key.");
throw new UserKeyNullException();
}
var decFolders = new List<FolderView>();
async Task decryptAndAddFolderAsync(Folder folder)

8
src/Core/Services/KeyConnectorService.cs

@ -68,14 +68,14 @@ namespace Bit.Core.Services @@ -68,14 +68,14 @@ namespace Bit.Core.Services
try
{
var keyConnectorRequest = new KeyConnectorUserKeyRequest(masterKey.EncKeyB64);
await _apiService.PostMasterKeyToKeyConnector(organization.KeyConnectorUrl, keyConnectorRequest);
await _apiService.PostMasterKeyToKeyConnectorAsync(organization.KeyConnectorUrl, keyConnectorRequest);
}
catch (Exception e)
{
throw new Exception("Unable to reach Key Connector", e);
}
await _apiService.PostConvertToKeyConnector();
await _apiService.PostConvertToKeyConnectorAsync();
}
public async Task<bool> UserNeedsMigrationAsync()
@ -103,7 +103,7 @@ namespace Bit.Core.Services @@ -103,7 +103,7 @@ namespace Bit.Core.Services
try
{
await _apiService.PostMasterKeyToKeyConnector(tokenResponse.KeyConnectorUrl, keyConnectorRequest);
await _apiService.PostMasterKeyToKeyConnectorAsync(tokenResponse.KeyConnectorUrl, keyConnectorRequest);
}
catch (Exception e)
{
@ -119,7 +119,7 @@ namespace Bit.Core.Services @@ -119,7 +119,7 @@ namespace Bit.Core.Services
var setPasswordRequest = new SetKeyConnectorKeyRequest(
newProtectedUserKey.EncryptedString, keys, tokenResponse.KdfConfig, orgId
);
await _apiService.PostSetKeyConnectorKey(setPasswordRequest);
await _apiService.PostSetKeyConnectorKeyAsync(setPasswordRequest);
}
}
}

Loading…
Cancel
Save