mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-27 12:26:31 +01:00
account apis
This commit is contained in:
parent
567161d8f3
commit
115fa349d2
8
src/Core/Models/Request/KeysRequest.cs
Normal file
8
src/Core/Models/Request/KeysRequest.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace Bit.Core.Models.Request
|
||||||
|
{
|
||||||
|
public class KeysRequest
|
||||||
|
{
|
||||||
|
public string PublicKey { get; set; }
|
||||||
|
public string EncryptedPrivateKey { get; set; }
|
||||||
|
}
|
||||||
|
}
|
7
src/Core/Models/Request/PasswordHintRequest.cs
Normal file
7
src/Core/Models/Request/PasswordHintRequest.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace Bit.Core.Models.Request
|
||||||
|
{
|
||||||
|
public class PasswordHintRequest
|
||||||
|
{
|
||||||
|
public string Email { get; set; }
|
||||||
|
}
|
||||||
|
}
|
7
src/Core/Models/Request/PreloginRequest.cs
Normal file
7
src/Core/Models/Request/PreloginRequest.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace Bit.Core.Models.Request
|
||||||
|
{
|
||||||
|
public class PreloginRequest
|
||||||
|
{
|
||||||
|
public string Email { get; set; }
|
||||||
|
}
|
||||||
|
}
|
19
src/Core/Models/Request/RegisterRequest.cs
Normal file
19
src/Core/Models/Request/RegisterRequest.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
10
src/Core/Models/Response/PreloginResponse.cs
Normal file
10
src/Core/Models/Response/PreloginResponse.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
20
src/Core/Models/Response/ProfileResponse.cs
Normal file
20
src/Core/Models/Response/ProfileResponse.cs
Normal file
@ -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<ProfileOrganizationResponse> Organizations { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ using Bit.Core.Models.Request;
|
|||||||
using Bit.Core.Models.Response;
|
using Bit.Core.Models.Response;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -17,6 +18,10 @@ namespace Bit.Core.Services
|
|||||||
{
|
{
|
||||||
public class ApiService
|
public class ApiService
|
||||||
{
|
{
|
||||||
|
private readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||||
|
};
|
||||||
private readonly HttpClient _httpClient = new HttpClient();
|
private readonly HttpClient _httpClient = new HttpClient();
|
||||||
private readonly ITokenService _tokenService;
|
private readonly ITokenService _tokenService;
|
||||||
private readonly IPlatformUtilsService _platformUtilsService;
|
private readonly IPlatformUtilsService _platformUtilsService;
|
||||||
@ -117,7 +122,41 @@ namespace Bit.Core.Services
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Account APIs
|
||||||
|
|
||||||
|
public async Task<ProfileResponse> GetProfileAsync()
|
||||||
|
{
|
||||||
|
return await SendAsync<object, ProfileResponse>(HttpMethod.Get, "/accounts/profile", null, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<PreloginResponse> PostPreloginAsync(PreloginRequest request)
|
||||||
|
{
|
||||||
|
return await SendAsync<PreloginRequest, PreloginResponse>(HttpMethod.Post, "/accounts/prelogin",
|
||||||
|
request, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<long> GetAccountRevisionDateAsync()
|
||||||
|
{
|
||||||
|
return await SendAsync<object, long>(HttpMethod.Get, "/accounts/revision-date", null, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task PostPasswordHintAsync(PasswordHintRequest request)
|
||||||
|
{
|
||||||
|
await SendAsync<PasswordHintRequest, object>(HttpMethod.Post, "/accounts/password-hint",
|
||||||
|
request, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task PostRegisterAsync(RegisterRequest request)
|
||||||
|
{
|
||||||
|
await SendAsync<RegisterRequest, object>(HttpMethod.Post, "/accounts/register", request, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task PostAccountKeysAsync(KeysRequest request)
|
||||||
|
{
|
||||||
|
await SendAsync<KeysRequest, object>(HttpMethod.Post, "/accounts/keys", request, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Helpers
|
#region Helpers
|
||||||
|
|
||||||
@ -155,7 +194,7 @@ namespace Bit.Core.Services
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(body),
|
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(body, _jsonSettings),
|
||||||
Encoding.UTF8, "application/json");
|
Encoding.UTF8, "application/json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user