From 115fa349d2df559b9200f691644d923ba6a946b3 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 10 Apr 2019 15:35:23 -0400 Subject: [PATCH] account apis --- ...eviceRequestModels.cs => DeviceRequest.cs} | 0 src/Core/Models/Request/KeysRequest.cs | 8 ++++ .../Models/Request/PasswordHintRequest.cs | 7 ++++ src/Core/Models/Request/PreloginRequest.cs | 7 ++++ src/Core/Models/Request/RegisterRequest.cs | 19 +++++++++ src/Core/Models/Response/PreloginResponse.cs | 10 +++++ src/Core/Models/Response/ProfileResponse.cs | 20 +++++++++ src/Core/Services/ApiService.cs | 41 ++++++++++++++++++- 8 files changed, 111 insertions(+), 1 deletion(-) rename src/Core/Models/Request/{DeviceRequestModels.cs => DeviceRequest.cs} (100%) create mode 100644 src/Core/Models/Request/KeysRequest.cs create mode 100644 src/Core/Models/Request/PasswordHintRequest.cs create mode 100644 src/Core/Models/Request/PreloginRequest.cs create mode 100644 src/Core/Models/Request/RegisterRequest.cs create mode 100644 src/Core/Models/Response/PreloginResponse.cs create mode 100644 src/Core/Models/Response/ProfileResponse.cs diff --git a/src/Core/Models/Request/DeviceRequestModels.cs b/src/Core/Models/Request/DeviceRequest.cs similarity index 100% rename from src/Core/Models/Request/DeviceRequestModels.cs rename to src/Core/Models/Request/DeviceRequest.cs diff --git a/src/Core/Models/Request/KeysRequest.cs b/src/Core/Models/Request/KeysRequest.cs new file mode 100644 index 000000000..9cae0a89d --- /dev/null +++ b/src/Core/Models/Request/KeysRequest.cs @@ -0,0 +1,8 @@ +namespace Bit.Core.Models.Request +{ + public class KeysRequest + { + public string PublicKey { get; set; } + public string EncryptedPrivateKey { get; set; } + } +} diff --git a/src/Core/Models/Request/PasswordHintRequest.cs b/src/Core/Models/Request/PasswordHintRequest.cs new file mode 100644 index 000000000..bd3389abb --- /dev/null +++ b/src/Core/Models/Request/PasswordHintRequest.cs @@ -0,0 +1,7 @@ +namespace Bit.Core.Models.Request +{ + public class PasswordHintRequest + { + public string Email { get; set; } + } +} diff --git a/src/Core/Models/Request/PreloginRequest.cs b/src/Core/Models/Request/PreloginRequest.cs new file mode 100644 index 000000000..13097a5b9 --- /dev/null +++ b/src/Core/Models/Request/PreloginRequest.cs @@ -0,0 +1,7 @@ +namespace Bit.Core.Models.Request +{ + public class PreloginRequest + { + public string Email { get; set; } + } +} diff --git a/src/Core/Models/Request/RegisterRequest.cs b/src/Core/Models/Request/RegisterRequest.cs new file mode 100644 index 000000000..959b1d988 --- /dev/null +++ b/src/Core/Models/Request/RegisterRequest.cs @@ -0,0 +1,19 @@ +using System; +using Bit.Core.Enums; + +namespace Bit.Core.Models.Request +{ + public class RegisterRequest + { + public string Name { get; set; } + public string Email { get; set; } + public string MasterPasswordHash { get; set; } + public string MasterPasswordHint { get; set; } + public string Key { get; set; } + public KeysRequest Keys { get; set; } + public string Token { get; set; } + public Guid? OrganizationUserId { get; set; } + public KdfType? Kdf { get; set; } + public int? KdfIterations { get; set; } + } +} diff --git a/src/Core/Models/Response/PreloginResponse.cs b/src/Core/Models/Response/PreloginResponse.cs new file mode 100644 index 000000000..33cf5c385 --- /dev/null +++ b/src/Core/Models/Response/PreloginResponse.cs @@ -0,0 +1,10 @@ +using Bit.Core.Enums; + +namespace Bit.Core.Models.Response +{ + public class PreloginResponse + { + public KdfType Kdf { get; set; } + public int KdfIterations { get; set; } + } +} diff --git a/src/Core/Models/Response/ProfileResponse.cs b/src/Core/Models/Response/ProfileResponse.cs new file mode 100644 index 000000000..07bd1ea70 --- /dev/null +++ b/src/Core/Models/Response/ProfileResponse.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace Bit.Core.Models.Response +{ + public class ProfileResponse + { + public string Id { get; set; } + public string Name { get; set; } + public string Email { get; set; } + public bool EmailVerified { get; set; } + public bool Premium { get; set; } + public string MasterPasswordHint { get; set; } + public string Culture { get; set; } + public bool TwoFactorEnabled { get; set; } + public string Key { get; set; } + public string PrivateKey { get; set; } + public string SecurityStamp { get; set; } + public List Organizations { get; set; } + } +} diff --git a/src/Core/Services/ApiService.cs b/src/Core/Services/ApiService.cs index 382055763..cb0c35961 100644 --- a/src/Core/Services/ApiService.cs +++ b/src/Core/Services/ApiService.cs @@ -5,6 +5,7 @@ using Bit.Core.Models.Request; using Bit.Core.Models.Response; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; using System; using System.Collections.Generic; using System.Linq; @@ -17,6 +18,10 @@ namespace Bit.Core.Services { public class ApiService { + private readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver() + }; private readonly HttpClient _httpClient = new HttpClient(); private readonly ITokenService _tokenService; private readonly IPlatformUtilsService _platformUtilsService; @@ -117,7 +122,41 @@ namespace Bit.Core.Services #endregion + #region Account APIs + public async Task GetProfileAsync() + { + return await SendAsync(HttpMethod.Get, "/accounts/profile", null, true, true); + } + + public async Task PostPreloginAsync(PreloginRequest request) + { + return await SendAsync(HttpMethod.Post, "/accounts/prelogin", + request, false, true); + } + + public async Task GetAccountRevisionDateAsync() + { + return await SendAsync(HttpMethod.Get, "/accounts/revision-date", null, true, true); + } + + public async Task PostPasswordHintAsync(PasswordHintRequest request) + { + await SendAsync(HttpMethod.Post, "/accounts/password-hint", + request, false, false); + } + + public async Task PostRegisterAsync(RegisterRequest request) + { + await SendAsync(HttpMethod.Post, "/accounts/register", request, false, false); + } + + public async Task PostAccountKeysAsync(KeysRequest request) + { + await SendAsync(HttpMethod.Post, "/accounts/keys", request, true, false); + } + + #endregion #region Helpers @@ -155,7 +194,7 @@ namespace Bit.Core.Services } else { - requestMessage.Content = new StringContent(JsonConvert.SerializeObject(body), + requestMessage.Content = new StringContent(JsonConvert.SerializeObject(body, _jsonSettings), Encoding.UTF8, "application/json"); } }