mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-23 11:45:38 +01:00
change login to cipher apis
This commit is contained in:
parent
15f074a45b
commit
e8486abccf
@ -220,7 +220,6 @@ namespace Bit.Android
|
||||
container.RegisterSingleton<IFolderApiRepository, FolderApiRepository>();
|
||||
container.RegisterSingleton<ILoginRepository, LoginRepository>();
|
||||
container.RegisterSingleton<IAttachmentRepository, AttachmentRepository>();
|
||||
container.RegisterSingleton<ILoginApiRepository, LoginApiRepository>();
|
||||
container.RegisterSingleton<IConnectApiRepository, ConnectApiRepository>();
|
||||
container.RegisterSingleton<IDeviceApiRepository, DeviceApiRepository>();
|
||||
container.RegisterSingleton<IAccountsApiRepository, AccountsApiRepository>();
|
||||
|
@ -4,10 +4,8 @@ using Bit.App.Models.Api;
|
||||
|
||||
namespace Bit.App.Abstractions
|
||||
{
|
||||
public interface ICipherApiRepository
|
||||
public interface ICipherApiRepository : IApiRepository<CipherRequest, CipherResponse, string>
|
||||
{
|
||||
Task<ApiResult<CipherResponse>> GetByIdAsync(string id);
|
||||
Task<ApiResult<ListResponse<CipherResponse>>> GetAsync();
|
||||
Task<ApiResult<CipherResponse>> PostAttachmentAsync(string cipherId, byte[] data, string fileName);
|
||||
Task<ApiResult> DeleteAttachmentAsync(string cipherId, string attachmentId);
|
||||
}
|
||||
|
@ -1,11 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.App.Models.Api;
|
||||
|
||||
namespace Bit.App.Abstractions
|
||||
{
|
||||
public interface ILoginApiRepository : IApiRepository<LoginRequest, LoginResponse, string>
|
||||
{
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ namespace Bit.App.Abstractions
|
||||
Task<IEnumerable<Login>> GetAllAsync();
|
||||
Task<IEnumerable<Login>> GetAllAsync(bool favorites);
|
||||
Task<Tuple<IEnumerable<Login>, IEnumerable<Login>>> GetAllAsync(string uriString);
|
||||
Task<ApiResult<LoginResponse>> SaveAsync(Login login);
|
||||
Task<ApiResult<CipherResponse>> SaveAsync(Login login);
|
||||
Task<ApiResult> DeleteAsync(string id);
|
||||
Task<byte[]> DownloadAndDecryptAttachmentAsync(string url, string orgId = null);
|
||||
Task<ApiResult<CipherResponse>> EncryptAndSaveAttachmentAsync(Login login, byte[] data, string fileName);
|
||||
|
@ -104,7 +104,7 @@
|
||||
<Compile Include="Models\Api\Request\DeviceRequest.cs" />
|
||||
<Compile Include="Models\Api\Request\TwoFactorEmailRequest.cs" />
|
||||
<Compile Include="Models\Api\Request\RegisterRequest.cs" />
|
||||
<Compile Include="Models\Api\Request\LoginRequest.cs" />
|
||||
<Compile Include="Models\Api\Request\CipherRequest.cs" />
|
||||
<Compile Include="Models\Api\Request\PasswordHintRequest.cs" />
|
||||
<Compile Include="Models\Api\Request\TokenRequest.cs" />
|
||||
<Compile Include="Models\Api\Response\AttachmentResponse.cs" />
|
||||
@ -114,7 +114,6 @@
|
||||
<Compile Include="Models\Api\Response\FolderResponse.cs" />
|
||||
<Compile Include="Models\Api\Response\ListResponse.cs" />
|
||||
<Compile Include="Models\Api\Response\DeviceResponse.cs" />
|
||||
<Compile Include="Models\Api\Response\LoginResponse.cs" />
|
||||
<Compile Include="Models\Api\Response\ProfileOrganizationResponse.cs" />
|
||||
<Compile Include="Models\Api\Response\KeysResponse.cs" />
|
||||
<Compile Include="Models\Api\Response\SyncResponse.cs" />
|
||||
@ -180,13 +179,11 @@
|
||||
<Compile Include="Repositories\BaseApiRepository.cs" />
|
||||
<Compile Include="Abstractions\Repositories\IApiRepository.cs" />
|
||||
<Compile Include="Abstractions\Repositories\IFolderApiRepository.cs" />
|
||||
<Compile Include="Abstractions\Repositories\ILoginApiRepository.cs" />
|
||||
<Compile Include="Abstractions\Repositories\IConnectApiRepository.cs" />
|
||||
<Compile Include="Repositories\DeviceApiRepository.cs" />
|
||||
<Compile Include="Repositories\CipherApiRepository.cs" />
|
||||
<Compile Include="Abstractions\Repositories\ICipherApiRepository.cs" />
|
||||
<Compile Include="Repositories\SettingsRepository.cs" />
|
||||
<Compile Include="Repositories\LoginApiRepository.cs" />
|
||||
<Compile Include="Repositories\FolderApiRepository.cs" />
|
||||
<Compile Include="Repositories\LoginRepository.cs" />
|
||||
<Compile Include="Repositories\FolderRepository.cs" />
|
||||
|
@ -1,9 +1,12 @@
|
||||
namespace Bit.App.Models.Api
|
||||
using Bit.App.Enums;
|
||||
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public class LoginRequest
|
||||
public class CipherRequest
|
||||
{
|
||||
public LoginRequest(Login login)
|
||||
public CipherRequest(Login login)
|
||||
{
|
||||
Type = CipherType.Login;
|
||||
OrganizationId = login.OrganizationId;
|
||||
FolderId = login.FolderId;
|
||||
Name = login.Name?.EncryptedString;
|
||||
@ -15,6 +18,7 @@
|
||||
Favorite = login.Favorite;
|
||||
}
|
||||
|
||||
public CipherType Type { get; set; }
|
||||
public string OrganizationId { get; set; }
|
||||
public string FolderId { get; set; }
|
||||
public string Name { get; set; }
|
@ -1,24 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public class LoginResponse
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string FolderId { get; set; }
|
||||
public string UserId { get; set; }
|
||||
public string OrganizationId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Uri { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public string Totp { get; set; }
|
||||
public bool Favorite { get; set; }
|
||||
public bool Edit { get; set; }
|
||||
public bool OrganizationUseTotp { get; set; }
|
||||
public IEnumerable<AttachmentResponse> Attachments { get; set; }
|
||||
public DateTime RevisionDate { get; set; }
|
||||
}
|
||||
}
|
@ -28,24 +28,6 @@ namespace Bit.App.Models.Data
|
||||
OrganizationUseTotp = login.OrganizationUseTotp;
|
||||
}
|
||||
|
||||
public LoginData(LoginResponse login, string userId)
|
||||
{
|
||||
Id = login.Id;
|
||||
FolderId = login.FolderId;
|
||||
UserId = userId;
|
||||
OrganizationId = login.OrganizationId;
|
||||
Name = login.Name;
|
||||
Uri = login.Uri;
|
||||
Username = login.Username;
|
||||
Password = login.Password;
|
||||
Notes = login.Notes;
|
||||
Totp = login.Totp;
|
||||
Favorite = login.Favorite;
|
||||
RevisionDateTime = login.RevisionDate;
|
||||
Edit = login.Edit;
|
||||
OrganizationUseTotp = login.OrganizationUseTotp;
|
||||
}
|
||||
|
||||
public LoginData(CipherResponse cipher, string userId)
|
||||
{
|
||||
if(cipher.Type != Enums.CipherType.Login)
|
||||
|
@ -28,24 +28,6 @@ namespace Bit.App.Models
|
||||
Attachments = attachments?.Select(a => new Attachment(a));
|
||||
}
|
||||
|
||||
public Login(LoginResponse response)
|
||||
{
|
||||
Id = response.Id;
|
||||
UserId = response.UserId;
|
||||
OrganizationId = response.OrganizationId;
|
||||
FolderId = response.FolderId;
|
||||
Name = response.Name != null ? new CipherString(response.Name) : null;
|
||||
Uri = response.Uri != null ? new CipherString(response.Uri) : null;
|
||||
Username = response.Username != null ? new CipherString(response.Username) : null;
|
||||
Password = response.Password != null ? new CipherString(response.Password) : null;
|
||||
Notes = response.Notes != null ? new CipherString(response.Notes) : null;
|
||||
Totp = response.Totp != null ? new CipherString(response.Totp) : null;
|
||||
Favorite = response.Favorite;
|
||||
Edit = response.Edit;
|
||||
OrganizationUseTotp = response.OrganizationUseTotp;
|
||||
Attachments = response.Attachments?.Select(a => new Attachment(a));
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string UserId { get; set; }
|
||||
public string OrganizationId { get; set; }
|
||||
@ -61,11 +43,6 @@ namespace Bit.App.Models
|
||||
public bool OrganizationUseTotp { get; set; }
|
||||
public IEnumerable<Attachment> Attachments { get; set; }
|
||||
|
||||
public LoginRequest ToLoginRequest()
|
||||
{
|
||||
return new LoginRequest(this);
|
||||
}
|
||||
|
||||
public LoginData ToLoginData(string userId)
|
||||
{
|
||||
return new LoginData(this, userId);
|
||||
|
@ -5,12 +5,11 @@ using Bit.App.Abstractions;
|
||||
using Bit.App.Models.Api;
|
||||
using Newtonsoft.Json;
|
||||
using Plugin.Connectivity.Abstractions;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
namespace Bit.App.Repositories
|
||||
{
|
||||
public class CipherApiRepository : BaseApiRepository, ICipherApiRepository
|
||||
public class CipherApiRepository : ApiRepository<CipherRequest, CipherResponse, string>, ICipherApiRepository
|
||||
{
|
||||
public CipherApiRepository(
|
||||
IConnectivity connectivity,
|
||||
@ -21,87 +20,6 @@ namespace Bit.App.Repositories
|
||||
|
||||
protected override string ApiRoute => "ciphers";
|
||||
|
||||
public virtual async Task<ApiResult<CipherResponse>> GetByIdAsync(string id)
|
||||
{
|
||||
if(!Connectivity.IsConnected)
|
||||
{
|
||||
return HandledNotConnected<CipherResponse>();
|
||||
}
|
||||
|
||||
var tokenStateResponse = await HandleTokenStateAsync<CipherResponse>();
|
||||
if(!tokenStateResponse.Succeeded)
|
||||
{
|
||||
return tokenStateResponse;
|
||||
}
|
||||
|
||||
using(var client = HttpService.ApiClient)
|
||||
{
|
||||
var requestMessage = new TokenHttpRequestMessage()
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(string.Concat(client.BaseAddress, ApiRoute, "/", id)),
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
if(!response.IsSuccessStatusCode)
|
||||
{
|
||||
return await HandleErrorAsync<CipherResponse>(response).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
var responseObj = JsonConvert.DeserializeObject<CipherResponse>(responseContent);
|
||||
return ApiResult<CipherResponse>.Success(responseObj, response.StatusCode);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return HandledWebException<CipherResponse>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual async Task<ApiResult<ListResponse<CipherResponse>>> GetAsync()
|
||||
{
|
||||
if(!Connectivity.IsConnected)
|
||||
{
|
||||
return HandledNotConnected<ListResponse<CipherResponse>>();
|
||||
}
|
||||
|
||||
var tokenStateResponse = await HandleTokenStateAsync<ListResponse<CipherResponse>>();
|
||||
if(!tokenStateResponse.Succeeded)
|
||||
{
|
||||
return tokenStateResponse;
|
||||
}
|
||||
|
||||
using(var client = HttpService.ApiClient)
|
||||
{
|
||||
var requestMessage = new TokenHttpRequestMessage()
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(string.Format("{0}{1}?includeFolders=false&includeShared=true",
|
||||
client.BaseAddress, ApiRoute)),
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
if(!response.IsSuccessStatusCode)
|
||||
{
|
||||
return await HandleErrorAsync<ListResponse<CipherResponse>>(response).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
var responseObj = JsonConvert.DeserializeObject<ListResponse<CipherResponse>>(responseContent);
|
||||
return ApiResult<ListResponse<CipherResponse>>.Success(responseObj, response.StatusCode);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return HandledWebException<ListResponse<CipherResponse>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual async Task<ApiResult<CipherResponse>> PostAttachmentAsync(string cipherId, byte[] data,
|
||||
string fileName)
|
||||
{
|
||||
|
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Models.Api;
|
||||
using Plugin.Connectivity.Abstractions;
|
||||
|
||||
namespace Bit.App.Repositories
|
||||
{
|
||||
public class LoginApiRepository : ApiRepository<LoginRequest, LoginResponse, string>, ILoginApiRepository
|
||||
{
|
||||
public LoginApiRepository(
|
||||
IConnectivity connectivity,
|
||||
IHttpService httpService,
|
||||
ITokenService tokenService)
|
||||
: base(connectivity, httpService, tokenService)
|
||||
{ }
|
||||
|
||||
protected override string ApiRoute => "logins";
|
||||
}
|
||||
}
|
@ -18,7 +18,6 @@ namespace Bit.App.Services
|
||||
private readonly ILoginRepository _loginRepository;
|
||||
private readonly IAttachmentRepository _attachmentRepository;
|
||||
private readonly IAuthService _authService;
|
||||
private readonly ILoginApiRepository _loginApiRepository;
|
||||
private readonly ICipherApiRepository _cipherApiRepository;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private readonly ICryptoService _cryptoService;
|
||||
@ -27,7 +26,6 @@ namespace Bit.App.Services
|
||||
ILoginRepository loginRepository,
|
||||
IAttachmentRepository attachmentRepository,
|
||||
IAuthService authService,
|
||||
ILoginApiRepository loginApiRepository,
|
||||
ICipherApiRepository cipherApiRepository,
|
||||
ISettingsService settingsService,
|
||||
ICryptoService cryptoService)
|
||||
@ -35,7 +33,6 @@ namespace Bit.App.Services
|
||||
_loginRepository = loginRepository;
|
||||
_attachmentRepository = attachmentRepository;
|
||||
_authService = authService;
|
||||
_loginApiRepository = loginApiRepository;
|
||||
_cipherApiRepository = cipherApiRepository;
|
||||
_settingsService = settingsService;
|
||||
_cryptoService = cryptoService;
|
||||
@ -215,18 +212,18 @@ namespace Bit.App.Services
|
||||
return new Tuple<IEnumerable<Login>, IEnumerable<Login>>(matchingLogins, matchingFuzzyLogins);
|
||||
}
|
||||
|
||||
public async Task<ApiResult<LoginResponse>> SaveAsync(Login login)
|
||||
public async Task<ApiResult<CipherResponse>> SaveAsync(Login login)
|
||||
{
|
||||
ApiResult<LoginResponse> response = null;
|
||||
var request = new LoginRequest(login);
|
||||
ApiResult<CipherResponse> response = null;
|
||||
var request = new CipherRequest(login);
|
||||
|
||||
if(login.Id == null)
|
||||
{
|
||||
response = await _loginApiRepository.PostAsync(request);
|
||||
response = await _cipherApiRepository.PostAsync(request);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await _loginApiRepository.PutAsync(login.Id, request);
|
||||
response = await _cipherApiRepository.PutAsync(login.Id, request);
|
||||
}
|
||||
|
||||
if(response.Succeeded)
|
||||
@ -253,7 +250,7 @@ namespace Bit.App.Services
|
||||
|
||||
public async Task<ApiResult> DeleteAsync(string id)
|
||||
{
|
||||
var response = await _loginApiRepository.DeleteAsync(id);
|
||||
var response = await _cipherApiRepository.DeleteAsync(id);
|
||||
if(response.Succeeded)
|
||||
{
|
||||
await _loginRepository.DeleteAsync(id);
|
||||
|
@ -294,7 +294,6 @@ namespace Bit.iOS.Extension
|
||||
container.RegisterSingleton<IFolderApiRepository, FolderApiRepository>();
|
||||
container.RegisterSingleton<ILoginRepository, LoginRepository>();
|
||||
container.RegisterSingleton<IAttachmentRepository, AttachmentRepository>();
|
||||
container.RegisterSingleton<ILoginApiRepository, LoginApiRepository>();
|
||||
container.RegisterSingleton<IConnectApiRepository, ConnectApiRepository>();
|
||||
container.RegisterSingleton<ISettingsRepository, SettingsRepository>();
|
||||
container.RegisterSingleton<IAccountsApiRepository, AccountsApiRepository>();
|
||||
|
@ -277,7 +277,6 @@ namespace Bit.iOS
|
||||
container.RegisterSingleton<IFolderApiRepository, FolderApiRepository>();
|
||||
container.RegisterSingleton<ILoginRepository, LoginRepository>();
|
||||
container.RegisterSingleton<IAttachmentRepository, AttachmentRepository>();
|
||||
container.RegisterSingleton<ILoginApiRepository, LoginApiRepository>();
|
||||
container.RegisterSingleton<IConnectApiRepository, ConnectApiRepository>();
|
||||
container.RegisterSingleton<IDeviceApiRepository, DeviceApiRepository>();
|
||||
container.RegisterSingleton<IAccountsApiRepository, AccountsApiRepository>();
|
||||
|
Loading…
Reference in New Issue
Block a user