2016-06-22 05:29:29 +03:00
|
|
|
|
using System;
|
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
|
|
|
|
|
namespace Bit.App.Services
|
|
|
|
|
{
|
|
|
|
|
public class AppIdService : IAppIdService
|
|
|
|
|
{
|
|
|
|
|
private const string AppIdKey = "appId";
|
2016-07-28 01:46:55 +03:00
|
|
|
|
private readonly ISecureStorageService _secureStorageService;
|
|
|
|
|
private Guid? _appId;
|
2016-06-22 05:29:29 +03:00
|
|
|
|
|
2016-07-28 01:46:55 +03:00
|
|
|
|
public AppIdService(ISecureStorageService secureStorageService)
|
2016-06-22 05:29:29 +03:00
|
|
|
|
{
|
2016-07-28 01:46:55 +03:00
|
|
|
|
_secureStorageService = secureStorageService;
|
2016-06-22 05:29:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string AppId
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-07-28 01:46:55 +03:00
|
|
|
|
if(_appId.HasValue)
|
2016-06-22 05:29:29 +03:00
|
|
|
|
{
|
2016-07-28 01:46:55 +03:00
|
|
|
|
return _appId.Value.ToString();
|
2016-06-22 05:29:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-28 01:46:55 +03:00
|
|
|
|
var appIdBytes = _secureStorageService.Retrieve(AppIdKey);
|
|
|
|
|
if(appIdBytes != null)
|
2016-06-22 05:29:29 +03:00
|
|
|
|
{
|
2016-07-28 01:46:55 +03:00
|
|
|
|
_appId = new Guid(appIdBytes);
|
|
|
|
|
return _appId.Value.ToString();
|
2016-06-22 05:29:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-28 01:46:55 +03:00
|
|
|
|
_appId = Guid.NewGuid();
|
|
|
|
|
_secureStorageService.Store(AppIdKey, _appId.Value.ToByteArray());
|
|
|
|
|
return _appId.Value.ToString();
|
2016-06-22 05:29:29 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|