From b25c8b08424127f6499cc811d3eabb01e6933334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bispo?= Date: Mon, 25 Sep 2023 16:28:58 +0100 Subject: [PATCH] [PM-3893] Make PreLogin and Register endpoint use identity endpoints (#2772) --- src/Core/Abstractions/IApiService.cs | 2 +- src/Core/Services/ApiService.cs | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Core/Abstractions/IApiService.cs b/src/Core/Abstractions/IApiService.cs index 528885ab6..9fc041b9c 100644 --- a/src/Core/Abstractions/IApiService.cs +++ b/src/Core/Abstractions/IApiService.cs @@ -49,7 +49,7 @@ namespace Bit.Core.Abstractions Task RefreshIdentityTokenAsync(); Task PreValidateSsoAsync(string identifier); Task SendAsync(HttpMethod method, string path, - TRequest body, bool authed, bool hasResponse, Action alterRequest, bool logoutOnUnauthorized = true); + TRequest body, bool authed, bool hasResponse, Action alterRequest, bool logoutOnUnauthorized = true, bool sendToIdentity = false); Task SendAsync(HttpRequestMessage requestMessage, CancellationToken cancellationToken = default); void SetUrls(EnvironmentUrls urls); [Obsolete("Mar 25 2021: This method has been deprecated in favor of direct uploads. This method still exists for backward compatibility with old server versions.")] diff --git a/src/Core/Services/ApiService.cs b/src/Core/Services/ApiService.cs index dc67f681d..8488e4b33 100644 --- a/src/Core/Services/ApiService.cs +++ b/src/Core/Services/ApiService.cs @@ -148,7 +148,7 @@ namespace Bit.Core.Services public Task PostPreloginAsync(PreloginRequest request) { return SendAsync(HttpMethod.Post, "/accounts/prelogin", - request, false, true); + request, false, true, sendToIdentity: true); } public Task GetAccountRevisionDateAsync() @@ -170,7 +170,7 @@ namespace Bit.Core.Services public Task PostRegisterAsync(RegisterRequest request) { - return SendAsync(HttpMethod.Post, "/accounts/register", request, false, false); + return SendAsync(HttpMethod.Post, "/accounts/register", request, false, false, sendToIdentity: true); } public Task PostAccountKeysAsync(KeysRequest request) @@ -663,14 +663,15 @@ namespace Bit.Core.Services public Task SendAsync(HttpMethod method, string path, bool authed) => SendAsync(method, path, null, authed, true); public async Task SendAsync(HttpMethod method, string path, TRequest body, - bool authed, bool hasResponse, Action alterRequest = null, bool logoutOnUnauthorized = true) + bool authed, bool hasResponse, Action alterRequest = null, bool logoutOnUnauthorized = true, bool sendToIdentity = false) { using (var requestMessage = new HttpRequestMessage()) { + var baseUrl = sendToIdentity ? IdentityBaseUrl : ApiBaseUrl; requestMessage.Version = new Version(1, 0); requestMessage.Method = method; - if (!Uri.IsWellFormedUriString(ApiBaseUrl, UriKind.Absolute)) + if (!Uri.IsWellFormedUriString(baseUrl, UriKind.Absolute)) { throw new ApiException(new ErrorResponse { @@ -680,7 +681,7 @@ namespace Bit.Core.Services }); } - requestMessage.RequestUri = new Uri(string.Concat(ApiBaseUrl, path)); + requestMessage.RequestUri = new Uri(string.Concat(baseUrl, path)); if (body != null) {