@@ -6,8 +6,15 @@ namespace Common.Core
6
6
public class SecureStorageBase
7
7
{
8
8
private string appGroupId ;
9
+ private string domainIdentifier ;
9
10
private const string InternalSettingFile = "userdata.out" ;
10
11
12
+ public SecureStorageBase ( string appGroupId , string domainIdentifier )
13
+ {
14
+ this . appGroupId = appGroupId ;
15
+ this . domainIdentifier = domainIdentifier ;
16
+ }
17
+
11
18
public SecureStorageBase ( string appGroupId )
12
19
{
13
20
this . appGroupId = appGroupId ;
@@ -31,6 +38,11 @@ public async Task SetAsync(string key, string value)
31
38
throw new ArgumentNullException ( nameof ( value ) ) ;
32
39
}
33
40
41
+ if ( ! string . IsNullOrEmpty ( domainIdentifier ) )
42
+ {
43
+ key = $ "{ domainIdentifier } -{ key } ";
44
+ }
45
+
34
46
// Because secure storage requires provisioning profile, in case of the development mode, we store credentials in external file.
35
47
string userDataPath = Path . Combine ( GetSharedContainerPath ( ) , InternalSettingFile ) ;
36
48
Dictionary < string , string > userData = File . Exists ( userDataPath ) ? JsonSerializer . Deserialize < Dictionary < string , string > > ( await File . ReadAllTextAsync ( userDataPath ) ) : new Dictionary < string , string > ( ) ;
@@ -61,15 +73,21 @@ public async Task SetAsync(string key, string value)
61
73
/// Returns value by key.
62
74
/// </summary>
63
75
/// <param name="key">Key.</param>
76
+ /// <param name="useDomainIdentifier">true if include domain identifier in, otherwise false. default is true.</param>
64
77
/// <returns></returns>
65
- public async Task < string > GetAsync ( string key )
78
+ public async Task < string > GetAsync ( string key , bool useDomainIdentifier = true )
66
79
{
67
80
string userDataPath = Path . Combine ( GetSharedContainerPath ( ) , InternalSettingFile ) ;
68
81
if ( File . Exists ( userDataPath ) )
69
82
{
70
83
string settingsContent = await File . ReadAllTextAsync ( userDataPath ) ;
71
84
Dictionary < string , string > userData = JsonSerializer . Deserialize < Dictionary < string , string > > ( settingsContent ) ;
72
85
86
+ if ( ! string . IsNullOrEmpty ( domainIdentifier ) && useDomainIdentifier )
87
+ {
88
+ key = $ "{ domainIdentifier } -{ key } ";
89
+ }
90
+
73
91
if ( userData . ContainsKey ( key ) )
74
92
{
75
93
return userData [ key ] ;
0 commit comments