mirror of
https://github.com/bitwarden/mobile
synced 2025-12-15 07:43:37 +00:00
[KeyConnector] Add support for key connector OTP (#1633)
* initial commit - add UsesKeyConnector to UserService - add models - begin work on authentication * finish auth workflow for key connector sso login - finish api call for get user key - start api calls for posts to key connector * Bypass lock page if already unlocked * Move logic to KeyConnectorService, log out if no pin or biometric is set * Disable password reprompt when using key connector * hide password reprompt checkbox when editing or adding cipher * add PostUserKey and PostSetKeyConnector calls * add ConvertMasterPasswordPage * add functionality to RemoveMasterPasswordPage - rename Convert to Remove * Hide Change Master Password button if using key connector * Add OTP verification for export component * Update src/App/Pages/Vault/AddEditPage.xaml.cs Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> * remove toolbar item "close" * Update src/Core/Models/Request/KeyConnectorUserKeyRequest.cs Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> * remove new line in resource string - format warning as two labels - set label in code behind for loading simultaneously * implement GetAndSetKey in KeyConnectorService - ignore EnvironmentService call * remove unnecesary orgIdentifier * move RemoveMasterPasswordPage call to LockPage * add spacing to export vault page * log out if no PIN or bio on lock page with key connector * Delete excessive whitespace * Delete excessive whitespace * Change capitalisation of OTP * add default value to models for backwards compatibility * remove this keyword * actually handle exceptions * move RemoveMasterPasswordPage to TabPage using messaging service * add minor improvements * remove 'this.' Co-authored-by: Hinton <oscar@oscarhinton.com> Co-authored-by: Thomas Rittson <trittson@bitwarden.com> Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com>
This commit is contained in:
@@ -178,12 +178,33 @@ namespace Bit.Core.Services
|
||||
true, false);
|
||||
}
|
||||
|
||||
public Task PostAccountRequestOTP()
|
||||
{
|
||||
return SendAsync<object, object>(HttpMethod.Post, "/accounts/request-otp", null, true, false);
|
||||
}
|
||||
|
||||
public Task PostAccountVerifyOTPAsync(VerifyOTPRequest request)
|
||||
{
|
||||
return SendAsync<VerifyOTPRequest, object>(HttpMethod.Post, "/accounts/verify-otp", request,
|
||||
true, false);
|
||||
}
|
||||
|
||||
public Task PutUpdateTempPasswordAsync(UpdateTempPasswordRequest request)
|
||||
{
|
||||
return SendAsync<UpdateTempPasswordRequest, object>(HttpMethod.Put, "/accounts/update-temp-password",
|
||||
request, true, false);
|
||||
}
|
||||
|
||||
|
||||
public Task PostConvertToKeyConnector()
|
||||
{
|
||||
return SendAsync<object, object>(HttpMethod.Post, "/accounts/convert-to-key-connector", null, true, false);
|
||||
}
|
||||
|
||||
public Task PostSetKeyConnectorKey(SetKeyConnectorKeyRequest request)
|
||||
{
|
||||
return SendAsync<SetKeyConnectorKeyRequest>(HttpMethod.Post, "/accounts/set-key-connector-key", request, true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Folder APIs
|
||||
@@ -422,9 +443,14 @@ namespace Bit.Core.Services
|
||||
return SendAsync<object, OrganizationAutoEnrollStatusResponse>(HttpMethod.Get,
|
||||
$"/organizations/{identifier}/auto-enroll-status", null, true, true);
|
||||
}
|
||||
|
||||
|
||||
public Task PostLeaveOrganization(string id)
|
||||
{
|
||||
return SendAsync<object, object>(HttpMethod.Post, $"/organizations/{id}/leave", null, true, false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Organization User APIs
|
||||
|
||||
public Task PutOrganizationUserResetPasswordEnrollmentAsync(string orgId, string userId,
|
||||
@@ -433,7 +459,71 @@ namespace Bit.Core.Services
|
||||
return SendAsync<OrganizationUserResetPasswordEnrollmentRequest, object>(HttpMethod.Put,
|
||||
$"/organizations/{orgId}/users/{userId}/reset-password-enrollment", request, true, false);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Key Connector
|
||||
|
||||
public async Task<KeyConnectorUserKeyResponse> GetUserKeyFromKeyConnector(string keyConnectorUrl)
|
||||
{
|
||||
using (var requestMessage = new HttpRequestMessage())
|
||||
{
|
||||
var authHeader = await GetActiveBearerTokenAsync();
|
||||
|
||||
requestMessage.Version = new Version(1, 0);
|
||||
requestMessage.Method = HttpMethod.Get;
|
||||
requestMessage.RequestUri = new Uri(string.Concat(keyConnectorUrl, "/user-keys"));
|
||||
requestMessage.Headers.Add("Authorization", string.Concat("Bearer ", authHeader));
|
||||
|
||||
HttpResponseMessage response;
|
||||
try
|
||||
{
|
||||
response = await _httpClient.SendAsync(requestMessage);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ApiException(HandleWebError(e));
|
||||
}
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var error = await HandleErrorAsync(response, false, true);
|
||||
throw new ApiException(error);
|
||||
}
|
||||
var responseJsonString = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<KeyConnectorUserKeyResponse>(responseJsonString);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task PostUserKeyToKeyConnector(string keyConnectorUrl, KeyConnectorUserKeyRequest request)
|
||||
{
|
||||
using (var requestMessage = new HttpRequestMessage())
|
||||
{
|
||||
var authHeader = await GetActiveBearerTokenAsync();
|
||||
|
||||
requestMessage.Version = new Version(1, 0);
|
||||
requestMessage.Method = HttpMethod.Post;
|
||||
requestMessage.RequestUri = new Uri(string.Concat(keyConnectorUrl, "/user-keys"));
|
||||
requestMessage.Headers.Add("Authorization", string.Concat("Bearer ", authHeader));
|
||||
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(request, _jsonSettings),
|
||||
Encoding.UTF8, "application/json");
|
||||
|
||||
HttpResponseMessage response;
|
||||
try
|
||||
{
|
||||
response = await _httpClient.SendAsync(requestMessage);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ApiException(HandleWebError(e));
|
||||
}
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var error = await HandleErrorAsync(response, false, true);
|
||||
throw new ApiException(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
Reference in New Issue
Block a user