mirror of
https://github.com/bitwarden/mobile
synced 2025-12-28 06:03:40 +00:00
stub out beginnings of apiservice
This commit is contained in:
9
src/Core/Models/Domain/EnvironmentUrls.cs
Normal file
9
src/Core/Models/Domain/EnvironmentUrls.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Bit.Core.Models.Domain
|
||||
{
|
||||
public class EnvironmentUrls
|
||||
{
|
||||
public string Base { get; set; }
|
||||
public string Api { get; set; }
|
||||
public string Identity { get; set; }
|
||||
}
|
||||
}
|
||||
21
src/Core/Models/Request/DeviceRequestModels.cs
Normal file
21
src/Core/Models/Request/DeviceRequestModels.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Core.Models.Request
|
||||
{
|
||||
public class DeviceRequest
|
||||
{
|
||||
public DeviceRequest(string appId, IPlatformUtilsService platformUtilsService)
|
||||
{
|
||||
Type = platformUtilsService.GetDevice();
|
||||
Name = platformUtilsService.GetDeviceString();
|
||||
Identifier = appId;
|
||||
PushToken = null; // TODO?
|
||||
}
|
||||
|
||||
public DeviceType? Type { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Identifier { get; set; }
|
||||
public string PushToken { get; set; }
|
||||
}
|
||||
}
|
||||
17
src/Core/Models/Request/TokenRequest.cs
Normal file
17
src/Core/Models/Request/TokenRequest.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Bit.Core.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Bit.Core.Models.Request
|
||||
{
|
||||
public class TokenRequest
|
||||
{
|
||||
public string Email { get; set; }
|
||||
public string MasterPasswordHash { get; set; }
|
||||
public string Token { get; set; }
|
||||
public TwoFactorProviderType Provider { get; set; }
|
||||
public bool Remember { get; set; }
|
||||
public DeviceRequest Device { get; set; }
|
||||
}
|
||||
}
|
||||
62
src/Core/Models/Response/ErrorResponse.cs
Normal file
62
src/Core/Models/Response/ErrorResponse.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
||||
namespace Bit.Core.Models.Response
|
||||
{
|
||||
public class ErrorResponse
|
||||
{
|
||||
public ErrorResponse(JObject response, HttpStatusCode status, bool identityResponse = false)
|
||||
{
|
||||
JObject errorModel = null;
|
||||
if(response != null)
|
||||
{
|
||||
var responseErrorModel = response.GetValue("ErrorModel", StringComparison.OrdinalIgnoreCase);
|
||||
if(responseErrorModel != null && identityResponse)
|
||||
{
|
||||
errorModel = responseErrorModel.Value<JObject>(); ;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorModel = response;
|
||||
}
|
||||
}
|
||||
if(errorModel != null)
|
||||
{
|
||||
Message = errorModel.GetValue("Message", StringComparison.OrdinalIgnoreCase)?.Value<string>();
|
||||
ValidationErrors = errorModel.GetValue("ValidationErrors", StringComparison.OrdinalIgnoreCase)
|
||||
?.Value<Dictionary<string, List<string>>>();
|
||||
}
|
||||
else
|
||||
{
|
||||
if((int)status == 429)
|
||||
{
|
||||
Message = "Rate limit exceeded. Try again later.";
|
||||
}
|
||||
}
|
||||
StatusCode = status;
|
||||
}
|
||||
|
||||
public string Message { get; set; }
|
||||
public Dictionary<string, List<string>> ValidationErrors { get; set; }
|
||||
public HttpStatusCode StatusCode { get; set; }
|
||||
|
||||
public string GetSingleMessage()
|
||||
{
|
||||
if(ValidationErrors == null)
|
||||
{
|
||||
return Message;
|
||||
}
|
||||
foreach(var error in ValidationErrors)
|
||||
{
|
||||
if(error.Value?.Any() ?? false)
|
||||
{
|
||||
return error.Value[0];
|
||||
}
|
||||
}
|
||||
return Message;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/Core/Models/Response/IdentityTokenResponse.cs
Normal file
13
src/Core/Models/Response/IdentityTokenResponse.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Bit.Core.Models.Response
|
||||
{
|
||||
public class IdentityTokenResponse
|
||||
{
|
||||
public string AccessToken { get; set; }
|
||||
public string ExpiresIn { get; set; }
|
||||
public string RefreshToken { get; set; }
|
||||
public string TokenType { get; set; }
|
||||
public string PrivateKey { get; set; }
|
||||
public string Key { get; set; }
|
||||
public string TwoFactorToken { get; set; }
|
||||
}
|
||||
}
|
||||
11
src/Core/Models/Response/IdentityTwoFactorResponse.cs
Normal file
11
src/Core/Models/Response/IdentityTwoFactorResponse.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Bit.Core.Enums;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Bit.Core.Models.Response
|
||||
{
|
||||
public class IdentityTwoFactorResponse
|
||||
{
|
||||
public List<TwoFactorProviderType> TwoFactorProviders { get; set; }
|
||||
public Dictionary<TwoFactorProviderType, Dictionary<string, object>> TwoFactorProviders2 { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user