mirror of
https://github.com/bitwarden/mobile.git
synced 2025-03-02 03:31:07 +01:00
app id service
This commit is contained in:
parent
6d22888bf6
commit
574c826036
10
src/Core/Abstractions/IAppIdService.cs
Normal file
10
src/Core/Abstractions/IAppIdService.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core.Abstractions
|
||||
{
|
||||
public interface IAppIdService
|
||||
{
|
||||
Task<string> GetAppIdAsync();
|
||||
Task<string> GetAnonymousAppIdAsync();
|
||||
}
|
||||
}
|
38
src/Core/Services/AppIdService.cs
Normal file
38
src/Core/Services/AppIdService.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using Bit.Core.Abstractions;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core.Services
|
||||
{
|
||||
public class AppIdService
|
||||
{
|
||||
private readonly IStorageService _storageService;
|
||||
|
||||
public AppIdService(IStorageService storageService)
|
||||
{
|
||||
_storageService = storageService;
|
||||
}
|
||||
|
||||
public Task<string> GetAppIdAsync()
|
||||
{
|
||||
return MakeAndGetAppIdAsync("appId");
|
||||
}
|
||||
|
||||
public Task<string> GetAnonymousAppIdAsync()
|
||||
{
|
||||
return MakeAndGetAppIdAsync("anonymousAppId");
|
||||
}
|
||||
|
||||
private async Task<string> MakeAndGetAppIdAsync(string key)
|
||||
{
|
||||
var existingId = await _storageService.GetAsync<string>(key);
|
||||
if(existingId != null)
|
||||
{
|
||||
return existingId;
|
||||
}
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
await _storageService.SaveAsync(key, guid);
|
||||
return guid;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user