-
Notifications
You must be signed in to change notification settings - Fork 334
/
AbstractPlatformProxy.cs
213 lines (179 loc) · 7.66 KB
/
AbstractPlatformProxy.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Threading.Tasks;
using Microsoft.Identity.Client.AuthScheme.PoP;
using Microsoft.Identity.Client.Cache;
using Microsoft.Identity.Client.Cache.CacheImpl;
using Microsoft.Identity.Client.Core;
using Microsoft.Identity.Client.Internal.Broker;
using Microsoft.Identity.Client.PlatformsCommon.Interfaces;
using Microsoft.Identity.Client.UI;
namespace Microsoft.Identity.Client.PlatformsCommon.Shared
{
internal abstract class AbstractPlatformProxy : IPlatformProxy
{
private readonly Lazy<string> _callingApplicationName;
private readonly Lazy<string> _callingApplicationVersion;
private readonly Lazy<ICryptographyManager> _cryptographyManager;
private readonly Lazy<string> _deviceId;
private readonly Lazy<string> _deviceModel;
private readonly Lazy<string> _operatingSystem;
private readonly Lazy<IPlatformLogger> _platformLogger;
private readonly Lazy<string> _processorArchitecture;
private readonly Lazy<string> _productName;
private readonly Lazy<string> _runtimeVersion;
protected AbstractPlatformProxy(ICoreLogger logger)
{
Logger = logger;
_deviceModel = new Lazy<string>(InternalGetDeviceModel);
_operatingSystem = new Lazy<string>(InternalGetOperatingSystem);
_processorArchitecture = new Lazy<string>(InternalGetProcessorArchitecture);
_callingApplicationName = new Lazy<string>(InternalGetCallingApplicationName);
_callingApplicationVersion = new Lazy<string>(InternalGetCallingApplicationVersion);
_deviceId = new Lazy<string>(InternalGetDeviceId);
_productName = new Lazy<string>(InternalGetProductName);
_cryptographyManager = new Lazy<ICryptographyManager>(InternalGetCryptographyManager);
_platformLogger = new Lazy<IPlatformLogger>(InternalGetPlatformLogger);
_runtimeVersion = new Lazy<string>(InternalGetRuntimeVersion);
}
protected IFeatureFlags OverloadFeatureFlags { get; set; }
protected ICoreLogger Logger { get; }
/// <inheritdoc />
public IWebUIFactory GetWebUiFactory(ApplicationConfiguration appConfig)
{
return appConfig.WebUiFactoryCreator != null ?
appConfig.WebUiFactoryCreator() :
CreateWebUiFactory();
}
/// <inheritdoc />
public string GetDeviceModel()
{
return _deviceModel.Value;
}
/// <inheritdoc />
public string GetOperatingSystem()
{
return _operatingSystem.Value;
}
/// <inheritdoc />
public string GetProcessorArchitecture()
{
return _processorArchitecture.Value;
}
/// <inheritdoc />
public abstract Task<string> GetUserPrincipalNameAsync();
/// <inheritdoc />
public string GetCallingApplicationName()
{
return _callingApplicationName.Value;
}
/// <inheritdoc />
public string GetCallingApplicationVersion()
{
return _callingApplicationVersion.Value;
}
/// <inheritdoc />
public string GetDeviceId()
{
return _deviceId.Value;
}
/// <inheritdoc />
public abstract string GetDefaultRedirectUri(string clientId, bool useRecommendedRedirectUri = false);
/// <inheritdoc />
public string GetProductName()
{
return _productName.Value;
}
/// <inheritdoc />
public string GetRuntimeVersion()
{
return _runtimeVersion.Value;
}
/// <inheritdoc />
public abstract ILegacyCachePersistence CreateLegacyCachePersistence();
public ITokenCacheAccessor UserTokenCacheAccessorForTest { get; set; }
public ITokenCacheAccessor AppTokenCacheAccessorForTest { get; set; }
/// <inheritdoc />
public virtual ITokenCacheAccessor CreateTokenCacheAccessor(bool isApplicationTokenCache = false)
{
if (isApplicationTokenCache)
{
return AppTokenCacheAccessorForTest ?? new InMemoryPartitionedAppTokenCacheAccessor(Logger);
}
else
{
return UserTokenCacheAccessorForTest ?? new InMemoryPartitionedUserTokenCacheAccessor(Logger);
}
}
/// <inheritdoc />
public ICryptographyManager CryptographyManager => _cryptographyManager.Value;
/// <inheritdoc />
public IPlatformLogger PlatformLogger => _platformLogger.Value;
protected abstract IWebUIFactory CreateWebUiFactory();
protected abstract IFeatureFlags CreateFeatureFlags();
protected abstract string InternalGetDeviceModel();
protected abstract string InternalGetOperatingSystem();
protected abstract string InternalGetProcessorArchitecture();
protected abstract string InternalGetCallingApplicationName();
protected abstract string InternalGetCallingApplicationVersion();
protected abstract string InternalGetDeviceId();
protected abstract string InternalGetProductName();
protected abstract ICryptographyManager InternalGetCryptographyManager();
protected abstract IPlatformLogger InternalGetPlatformLogger();
// RuntimeInformation.FrameworkDescription is available on all platforms except .NET Framework 4.7 and lower.
protected virtual string InternalGetRuntimeVersion()
{
#if !DESKTOP
return System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
#else
return string.Empty; // For DESKTOP this should not be hit, since NetDesktopPlatformProxy will take over
#endif
}
public virtual ICacheSerializationProvider CreateTokenCacheBlobStorage()
{
return null;
}
// MATS properties
public abstract string GetDevicePlatformTelemetryId();
public abstract string GetDeviceNetworkState();
public abstract int GetMatsOsPlatformCode();
public abstract string GetMatsOsPlatform();
public virtual IFeatureFlags GetFeatureFlags()
{
return OverloadFeatureFlags ?? CreateFeatureFlags();
}
public void SetFeatureFlags(IFeatureFlags featureFlags)
{
OverloadFeatureFlags = featureFlags;
}
public virtual Task StartDefaultOsBrowserAsync(string url)
{
throw new NotImplementedException();
}
public virtual IBroker CreateBroker(ApplicationConfiguration appConfig, CoreUIParent uiParent)
{
return appConfig.BrokerCreatorFunc != null ?
appConfig.BrokerCreatorFunc(uiParent, appConfig, Logger) :
new NullBroker(Logger);
}
public virtual bool BrokerSupportsWamAccounts => false;
public virtual IPoPCryptoProvider GetDefaultPoPCryptoProvider()
{
throw new NotImplementedException();
}
public virtual IDeviceAuthManager CreateDeviceAuthManager()
{
return new NullDeviceAuthManager();
}
public virtual IMsalHttpClientFactory CreateDefaultHttpClientFactory()
{
return new SimpleHttpClientFactory();
}
/// <summary>
/// On Android, iOS and UWP, MSAL will save the legacy ADAL cache in a known location.
/// On other platforms, the app developer must use the serialization callbacks
/// </summary>
public virtual bool LegacyCacheRequiresSerialization => true;
}
}