1
0
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:
Kyle Spearrin
2019-04-10 10:49:24 -04:00
parent 0d417b3eee
commit 579a7e0398
10 changed files with 279 additions and 1 deletions

View 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; }
}
}

View 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; }
}
}

View 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; }
}
}

View 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;
}
}
}

View 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; }
}
}

View 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; }
}
}