mirror of
https://github.com/bitwarden/mobile
synced 2025-12-23 03:33:59 +00:00
build identity store for quick type bar
This commit is contained in:
@@ -23,7 +23,6 @@ namespace Bit.iOS.Core.Controllers
|
||||
private IConnectivity _connectivity;
|
||||
private IEnumerable<Folder> _folders;
|
||||
protected IGoogleAnalyticsService _googleAnalyticsService;
|
||||
private bool _isAutofill;
|
||||
|
||||
public LoginAddViewController(IntPtr handle) : base(handle)
|
||||
{
|
||||
|
||||
72
src/iOS.Core/Utilities/ASHelpers.cs
Normal file
72
src/iOS.Core/Utilities/ASHelpers.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AuthenticationServices;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Models;
|
||||
|
||||
namespace Bit.iOS.Core.Utilities
|
||||
{
|
||||
public static class ASHelpers
|
||||
{
|
||||
public static async Task ReplaceAllIdentities(ICipherService cipherService)
|
||||
{
|
||||
if (await AutofillEnabled())
|
||||
{
|
||||
var identities = new List<ASPasswordCredentialIdentity>();
|
||||
var ciphers = await cipherService.GetAllAsync();
|
||||
foreach (var cipher in ciphers)
|
||||
{
|
||||
var identity = ToCredentialIdentity(cipher);
|
||||
if (identity != null)
|
||||
{
|
||||
identities.Add(identity);
|
||||
}
|
||||
}
|
||||
if (identities.Any())
|
||||
{
|
||||
await ASCredentialIdentityStore.SharedStore.ReplaceCredentialIdentitiesAsync(identities.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<bool> IdentitiesCanIncremental()
|
||||
{
|
||||
var state = await ASCredentialIdentityStore.SharedStore.GetCredentialIdentityStoreStateAsync();
|
||||
return state.Enabled && state.SupportsIncrementalUpdates;
|
||||
}
|
||||
|
||||
public static async Task<bool> AutofillEnabled()
|
||||
{
|
||||
var state = await ASCredentialIdentityStore.SharedStore.GetCredentialIdentityStoreStateAsync();
|
||||
return state.Enabled;
|
||||
}
|
||||
|
||||
public static async Task<ASPasswordCredentialIdentity> GetCipherIdentityAsync(string cipherId, ICipherService cipherService)
|
||||
{
|
||||
var cipher = await cipherService.GetByIdAsync(cipherId);
|
||||
return ToCredentialIdentity(cipher);
|
||||
}
|
||||
|
||||
public static ASPasswordCredentialIdentity ToCredentialIdentity(Cipher cipher)
|
||||
{
|
||||
if (!cipher?.Login?.Uris?.Any() ?? true)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var uri = cipher.Login.Uris.FirstOrDefault()?.Uri?.Decrypt(cipher.OrganizationId);
|
||||
if (string.IsNullOrWhiteSpace(uri))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var username = cipher.Login.Username?.Decrypt(cipher.OrganizationId);
|
||||
if (string.IsNullOrWhiteSpace(username))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var serviceId = new ASCredentialServiceIdentifier(uri, ASCredentialServiceIdentifierType.Url);
|
||||
return new ASPasswordCredentialIdentity(serviceId, username, cipher.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,7 @@
|
||||
<Compile Include="Views\FormEntryTableViewCell.cs" />
|
||||
<Compile Include="Views\Toast.cs" />
|
||||
<Compile Include="Models\CipherViewModel.cs" />
|
||||
<Compile Include="Utilities\ASHelpers.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\App\App.csproj">
|
||||
|
||||
Reference in New Issue
Block a user