mirror of
https://github.com/bitwarden/mobile
synced 2025-12-15 07:43:37 +00:00
Added SSO flows and functionality (#1047)
* SSO login flow for pre-existing user and no 2FA * 2FA progress * 2FA support * Added SSO flows and functionality * Handle webauthenticator cancellation gracefully * updates & bugfixes * Added state validation to web auth response handling * SSO auth, account registration, and environment settings support for iOS extensions * Added SSO prevalidation to auth process * prevalidation now hitting identity service base url * additional error handling * Requested changes * fixed case
This commit is contained in:
@@ -165,6 +165,12 @@ namespace Bit.Core.Services
|
||||
request, false, false);
|
||||
}
|
||||
|
||||
public Task SetPasswordAsync(SetPasswordRequest request)
|
||||
{
|
||||
return SendAsync<SetPasswordRequest, object>(HttpMethod.Post, "/accounts/set-password", request, true,
|
||||
false);
|
||||
}
|
||||
|
||||
public Task PostRegisterAsync(RegisterRequest request)
|
||||
{
|
||||
return SendAsync<RegisterRequest, object>(HttpMethod.Post, "/accounts/register", request, false, false);
|
||||
@@ -175,6 +181,12 @@ namespace Bit.Core.Services
|
||||
return SendAsync<KeysRequest, object>(HttpMethod.Post, "/accounts/keys", request, true, false);
|
||||
}
|
||||
|
||||
public Task PostAccountVerifyPasswordAsync(PasswordVerificationRequest request)
|
||||
{
|
||||
return SendAsync<PasswordVerificationRequest, object>(HttpMethod.Post, "/accounts/verify-password", request,
|
||||
true, false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Folder APIs
|
||||
@@ -365,6 +377,34 @@ namespace Bit.Core.Services
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public async Task<object> PreValidateSso(string identifier)
|
||||
{
|
||||
var path = "/account/prevalidate?domainHint=" + WebUtility.UrlEncode(identifier);
|
||||
using (var requestMessage = new HttpRequestMessage())
|
||||
{
|
||||
requestMessage.Version = new Version(1, 0);
|
||||
requestMessage.Method = HttpMethod.Get;
|
||||
requestMessage.RequestUri = new Uri(string.Concat(IdentityBaseUrl, path));
|
||||
requestMessage.Headers.Add("Accept", "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);
|
||||
throw new ApiException(error);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<TResponse> SendAsync<TRequest, TResponse>(HttpMethod method, string path, TRequest body,
|
||||
bool authed, bool hasResponse)
|
||||
{
|
||||
@@ -488,13 +528,20 @@ namespace Bit.Core.Services
|
||||
await _logoutCallbackAsync(true);
|
||||
return null;
|
||||
}
|
||||
JObject responseJObject = null;
|
||||
if (IsJsonResponse(response))
|
||||
try
|
||||
{
|
||||
var responseJsonString = await response.Content.ReadAsStringAsync();
|
||||
responseJObject = JObject.Parse(responseJsonString);
|
||||
JObject responseJObject = null;
|
||||
if (IsJsonResponse(response))
|
||||
{
|
||||
var responseJsonString = await response.Content.ReadAsStringAsync();
|
||||
responseJObject = JObject.Parse(responseJsonString);
|
||||
}
|
||||
return new ErrorResponse(responseJObject, response.StatusCode, tokenError);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ErrorResponse(responseJObject, response.StatusCode, tokenError);
|
||||
}
|
||||
|
||||
private bool IsJsonResponse(HttpResponseMessage response)
|
||||
|
||||
Reference in New Issue
Block a user