@azure/msal-common 14.0.1 → 14.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (295) hide show
  1. package/dist/account/AuthToken.d.ts +14 -17
  2. package/dist/account/AuthToken.d.ts.map +1 -1
  3. package/dist/account/AuthToken.mjs +48 -39
  4. package/dist/account/AuthToken.mjs.map +1 -1
  5. package/dist/account/CcsCredential.mjs +1 -1
  6. package/dist/account/CcsCredential.mjs.map +1 -1
  7. package/dist/account/ClientInfo.d.ts.map +1 -1
  8. package/dist/account/ClientInfo.mjs +3 -4
  9. package/dist/account/ClientInfo.mjs.map +1 -1
  10. package/dist/authority/Authority.d.ts +1 -0
  11. package/dist/authority/Authority.d.ts.map +1 -1
  12. package/dist/authority/Authority.mjs +4 -2
  13. package/dist/authority/Authority.mjs.map +1 -1
  14. package/dist/authority/AuthorityFactory.d.ts +1 -0
  15. package/dist/authority/AuthorityFactory.d.ts.map +1 -1
  16. package/dist/authority/AuthorityFactory.mjs +3 -3
  17. package/dist/authority/AuthorityFactory.mjs.map +1 -1
  18. package/dist/authority/AuthorityMetadata.mjs +1 -1
  19. package/dist/authority/AuthorityMetadata.mjs.map +1 -1
  20. package/dist/authority/AuthorityOptions.mjs +1 -1
  21. package/dist/authority/AuthorityOptions.mjs.map +1 -1
  22. package/dist/authority/AuthorityType.mjs +1 -1
  23. package/dist/authority/AuthorityType.mjs.map +1 -1
  24. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
  25. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs.map +1 -1
  26. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
  27. package/dist/authority/CloudInstanceDiscoveryResponse.mjs.map +1 -1
  28. package/dist/authority/OpenIdConfigResponse.mjs +1 -1
  29. package/dist/authority/OpenIdConfigResponse.mjs.map +1 -1
  30. package/dist/authority/ProtocolMode.mjs +1 -1
  31. package/dist/authority/ProtocolMode.mjs.map +1 -1
  32. package/dist/authority/RegionDiscovery.mjs +1 -1
  33. package/dist/authority/RegionDiscovery.mjs.map +1 -1
  34. package/dist/cache/CacheManager.d.ts +2 -0
  35. package/dist/cache/CacheManager.d.ts.map +1 -1
  36. package/dist/cache/CacheManager.mjs +7 -5
  37. package/dist/cache/CacheManager.mjs.map +1 -1
  38. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  39. package/dist/cache/entities/AccessTokenEntity.mjs +4 -7
  40. package/dist/cache/entities/AccessTokenEntity.mjs.map +1 -1
  41. package/dist/cache/entities/AccountEntity.d.ts +1 -0
  42. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  43. package/dist/cache/entities/AccountEntity.mjs +3 -4
  44. package/dist/cache/entities/AccountEntity.mjs.map +1 -1
  45. package/dist/cache/entities/AppMetadataEntity.mjs +1 -1
  46. package/dist/cache/entities/AppMetadataEntity.mjs.map +1 -1
  47. package/dist/cache/entities/AuthorityMetadataEntity.d.ts +1 -0
  48. package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -1
  49. package/dist/cache/entities/AuthorityMetadataEntity.mjs +2 -1
  50. package/dist/cache/entities/AuthorityMetadataEntity.mjs.map +1 -1
  51. package/dist/cache/entities/CacheRecord.d.ts +1 -0
  52. package/dist/cache/entities/CacheRecord.d.ts.map +1 -1
  53. package/dist/cache/entities/CacheRecord.mjs +2 -1
  54. package/dist/cache/entities/CacheRecord.mjs.map +1 -1
  55. package/dist/cache/entities/CredentialEntity.mjs +1 -1
  56. package/dist/cache/entities/CredentialEntity.mjs.map +1 -1
  57. package/dist/cache/entities/IdTokenEntity.mjs +1 -1
  58. package/dist/cache/entities/IdTokenEntity.mjs.map +1 -1
  59. package/dist/cache/entities/RefreshTokenEntity.mjs +1 -1
  60. package/dist/cache/entities/RefreshTokenEntity.mjs.map +1 -1
  61. package/dist/cache/entities/ServerTelemetryEntity.mjs +1 -1
  62. package/dist/cache/entities/ServerTelemetryEntity.mjs.map +1 -1
  63. package/dist/cache/entities/ThrottlingEntity.mjs +1 -1
  64. package/dist/cache/entities/ThrottlingEntity.mjs.map +1 -1
  65. package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
  66. package/dist/cache/persistence/TokenCacheContext.mjs.map +1 -1
  67. package/dist/cache/utils/CacheTypes.d.ts +7 -0
  68. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  69. package/dist/client/AuthorizationCodeClient.d.ts +1 -0
  70. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  71. package/dist/client/AuthorizationCodeClient.mjs +11 -39
  72. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  73. package/dist/client/BaseClient.d.ts +2 -1
  74. package/dist/client/BaseClient.d.ts.map +1 -1
  75. package/dist/client/BaseClient.mjs +9 -2
  76. package/dist/client/BaseClient.mjs.map +1 -1
  77. package/dist/client/RefreshTokenClient.d.ts +1 -0
  78. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  79. package/dist/client/RefreshTokenClient.mjs +3 -11
  80. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  81. package/dist/client/SilentFlowClient.d.ts +1 -0
  82. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  83. package/dist/client/SilentFlowClient.mjs +8 -7
  84. package/dist/client/SilentFlowClient.mjs.map +1 -1
  85. package/dist/config/ClientConfiguration.d.ts +2 -0
  86. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  87. package/dist/config/ClientConfiguration.mjs +1 -1
  88. package/dist/config/ClientConfiguration.mjs.map +1 -1
  89. package/dist/crypto/ICrypto.mjs +1 -1
  90. package/dist/crypto/ICrypto.mjs.map +1 -1
  91. package/dist/crypto/JoseHeader.d.ts +1 -0
  92. package/dist/crypto/JoseHeader.d.ts.map +1 -1
  93. package/dist/crypto/JoseHeader.mjs +2 -1
  94. package/dist/crypto/JoseHeader.mjs.map +1 -1
  95. package/dist/crypto/PopTokenGenerator.d.ts +1 -0
  96. package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
  97. package/dist/crypto/PopTokenGenerator.mjs +2 -1
  98. package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
  99. package/dist/error/AuthError.mjs +1 -1
  100. package/dist/error/AuthError.mjs.map +1 -1
  101. package/dist/error/ClientAuthError.mjs +1 -1
  102. package/dist/error/ClientAuthError.mjs.map +1 -1
  103. package/dist/error/ClientConfigurationError.mjs +1 -1
  104. package/dist/error/ClientConfigurationError.mjs.map +1 -1
  105. package/dist/error/InteractionRequiredAuthError.mjs +1 -1
  106. package/dist/error/InteractionRequiredAuthError.mjs.map +1 -1
  107. package/dist/error/JoseHeaderError.mjs +1 -1
  108. package/dist/error/JoseHeaderError.mjs.map +1 -1
  109. package/dist/error/ServerError.mjs +1 -1
  110. package/dist/error/ServerError.mjs.map +1 -1
  111. package/dist/index.cjs +1926 -1826
  112. package/dist/index.cjs.map +1 -1
  113. package/dist/index.d.ts +4 -3
  114. package/dist/index.d.ts.map +1 -1
  115. package/dist/index.mjs +5 -3
  116. package/dist/index.mjs.map +1 -1
  117. package/dist/logger/Logger.d.ts.map +1 -1
  118. package/dist/logger/Logger.mjs +2 -12
  119. package/dist/logger/Logger.mjs.map +1 -1
  120. package/dist/network/INetworkModule.mjs +1 -1
  121. package/dist/network/INetworkModule.mjs.map +1 -1
  122. package/dist/network/NetworkManager.d.ts +1 -0
  123. package/dist/network/NetworkManager.d.ts.map +1 -1
  124. package/dist/network/NetworkManager.mjs +2 -1
  125. package/dist/network/NetworkManager.mjs.map +1 -1
  126. package/dist/network/ThrottlingUtils.d.ts +1 -0
  127. package/dist/network/ThrottlingUtils.d.ts.map +1 -1
  128. package/dist/network/ThrottlingUtils.mjs +2 -1
  129. package/dist/network/ThrottlingUtils.mjs.map +1 -1
  130. package/dist/packageMetadata.d.ts +1 -1
  131. package/dist/packageMetadata.mjs +2 -2
  132. package/dist/packageMetadata.mjs.map +1 -1
  133. package/dist/request/AuthenticationHeaderParser.mjs +1 -1
  134. package/dist/request/AuthenticationHeaderParser.mjs.map +1 -1
  135. package/dist/request/RequestParameterBuilder.d.ts +1 -0
  136. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  137. package/dist/request/RequestParameterBuilder.mjs +7 -7
  138. package/dist/request/RequestParameterBuilder.mjs.map +1 -1
  139. package/dist/request/RequestValidator.d.ts.map +1 -1
  140. package/dist/request/RequestValidator.mjs +4 -6
  141. package/dist/request/RequestValidator.mjs.map +1 -1
  142. package/dist/request/ScopeSet.mjs +4 -4
  143. package/dist/request/ScopeSet.mjs.map +1 -1
  144. package/dist/response/AuthenticationResult.d.ts +3 -1
  145. package/dist/response/AuthenticationResult.d.ts.map +1 -1
  146. package/dist/response/ResponseHandler.d.ts +5 -3
  147. package/dist/response/ResponseHandler.d.ts.map +1 -1
  148. package/dist/response/ResponseHandler.mjs +58 -39
  149. package/dist/response/ResponseHandler.mjs.map +1 -1
  150. package/dist/response/ServerAuthorizationTokenResponse.d.ts +2 -0
  151. package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
  152. package/dist/telemetry/performance/IPerformanceClient.d.ts +4 -4
  153. package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
  154. package/dist/telemetry/performance/PerformanceClient.d.ts +2 -2
  155. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  156. package/dist/telemetry/performance/PerformanceClient.mjs +1 -1
  157. package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
  158. package/dist/telemetry/performance/PerformanceEvent.d.ts +8 -1
  159. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  160. package/dist/telemetry/performance/PerformanceEvent.mjs +9 -1
  161. package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
  162. package/dist/telemetry/performance/StubPerformanceClient.d.ts +3 -3
  163. package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -1
  164. package/dist/telemetry/performance/StubPerformanceClient.mjs +23 -3
  165. package/dist/telemetry/performance/StubPerformanceClient.mjs.map +1 -1
  166. package/dist/telemetry/server/ServerTelemetryManager.d.ts +1 -0
  167. package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
  168. package/dist/telemetry/server/ServerTelemetryManager.mjs +4 -4
  169. package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
  170. package/dist/url/UrlString.d.ts.map +1 -1
  171. package/dist/url/UrlString.mjs +10 -12
  172. package/dist/url/UrlString.mjs.map +1 -1
  173. package/dist/utils/Constants.d.ts +10 -0
  174. package/dist/utils/Constants.d.ts.map +1 -1
  175. package/dist/utils/Constants.mjs +11 -2
  176. package/dist/utils/Constants.mjs.map +1 -1
  177. package/dist/utils/FunctionWrappers.d.ts +28 -0
  178. package/dist/utils/FunctionWrappers.d.ts.map +1 -0
  179. package/dist/utils/FunctionWrappers.mjs +90 -0
  180. package/dist/utils/FunctionWrappers.mjs.map +1 -0
  181. package/dist/utils/ProtocolUtils.d.ts.map +1 -1
  182. package/dist/utils/ProtocolUtils.mjs +4 -7
  183. package/dist/utils/ProtocolUtils.mjs.map +1 -1
  184. package/dist/utils/StringUtils.d.ts +0 -13
  185. package/dist/utils/StringUtils.d.ts.map +1 -1
  186. package/dist/utils/StringUtils.mjs +3 -34
  187. package/dist/utils/StringUtils.mjs.map +1 -1
  188. package/dist/utils/TimeUtils.mjs +1 -1
  189. package/dist/utils/TimeUtils.mjs.map +1 -1
  190. package/package.json +6 -4
  191. package/src/account/AccountInfo.ts +44 -0
  192. package/src/account/AuthToken.ts +70 -0
  193. package/src/account/CcsCredential.ts +16 -0
  194. package/src/account/ClientCredentials.ts +20 -0
  195. package/src/account/ClientInfo.ts +64 -0
  196. package/src/account/TokenClaims.ts +70 -0
  197. package/src/authority/Authority.ts +1225 -0
  198. package/src/authority/AuthorityFactory.ts +106 -0
  199. package/src/authority/AuthorityMetadata.ts +953 -0
  200. package/src/authority/AuthorityOptions.ts +40 -0
  201. package/src/authority/AuthorityType.ts +15 -0
  202. package/src/authority/AzureRegion.ts +7 -0
  203. package/src/authority/AzureRegionConfiguration.ts +16 -0
  204. package/src/authority/CloudDiscoveryMetadata.ts +10 -0
  205. package/src/authority/CloudInstanceDiscoveryErrorResponse.ts +26 -0
  206. package/src/authority/CloudInstanceDiscoveryResponse.ts +21 -0
  207. package/src/authority/ImdsOptions.ts +10 -0
  208. package/src/authority/OIDCOptions.ts +14 -0
  209. package/src/authority/OpenIdConfigResponse.ts +24 -0
  210. package/src/authority/ProtocolMode.ts +13 -0
  211. package/src/authority/RegionDiscovery.ts +193 -0
  212. package/src/authority/RegionDiscoveryMetadata.ts +15 -0
  213. package/src/broker/nativeBroker/INativeBrokerPlugin.ts +29 -0
  214. package/src/cache/CacheManager.ts +1619 -0
  215. package/src/cache/entities/AccessTokenEntity.ts +162 -0
  216. package/src/cache/entities/AccountEntity.ts +309 -0
  217. package/src/cache/entities/AppMetadataEntity.ts +91 -0
  218. package/src/cache/entities/AuthorityMetadataEntity.ts +112 -0
  219. package/src/cache/entities/CacheRecord.ts +33 -0
  220. package/src/cache/entities/CredentialEntity.ts +215 -0
  221. package/src/cache/entities/IdTokenEntity.ts +74 -0
  222. package/src/cache/entities/RefreshTokenEntity.ts +78 -0
  223. package/src/cache/entities/ServerTelemetryEntity.ts +38 -0
  224. package/src/cache/entities/ThrottlingEntity.ts +36 -0
  225. package/src/cache/interface/ICacheManager.ts +218 -0
  226. package/src/cache/interface/ICachePlugin.ts +11 -0
  227. package/src/cache/interface/ISerializableTokenCache.ts +9 -0
  228. package/src/cache/persistence/TokenCacheContext.ts +39 -0
  229. package/src/cache/utils/CacheTypes.ts +93 -0
  230. package/src/client/AuthorizationCodeClient.ts +714 -0
  231. package/src/client/BaseClient.ts +205 -0
  232. package/src/client/RefreshTokenClient.ts +442 -0
  233. package/src/client/SilentFlowClient.ts +186 -0
  234. package/src/config/AppTokenProvider.ts +47 -0
  235. package/src/config/ClientConfiguration.ts +287 -0
  236. package/src/crypto/ICrypto.ts +127 -0
  237. package/src/crypto/IGuidGenerator.ts +9 -0
  238. package/src/crypto/JoseHeader.ts +55 -0
  239. package/src/crypto/PopTokenGenerator.ts +155 -0
  240. package/src/crypto/SignedHttpRequest.ts +16 -0
  241. package/src/error/AuthError.ts +85 -0
  242. package/src/error/ClientAuthError.ts +738 -0
  243. package/src/error/ClientConfigurationError.ts +396 -0
  244. package/src/error/InteractionRequiredAuthError.ts +134 -0
  245. package/src/error/JoseHeaderError.ts +52 -0
  246. package/src/error/ServerError.ts +18 -0
  247. package/src/index.ts +215 -0
  248. package/src/logger/Logger.ts +272 -0
  249. package/src/network/INetworkModule.ts +57 -0
  250. package/src/network/NetworkManager.ts +76 -0
  251. package/src/network/RequestThumbprint.ts +22 -0
  252. package/src/network/ThrottlingUtils.ts +156 -0
  253. package/src/packageMetadata.ts +3 -0
  254. package/src/request/AuthenticationHeaderParser.ts +89 -0
  255. package/src/request/BaseAuthRequest.ts +46 -0
  256. package/src/request/CommonAuthorizationCodeRequest.ts +33 -0
  257. package/src/request/CommonAuthorizationUrlRequest.ts +56 -0
  258. package/src/request/CommonClientCredentialRequest.ts +23 -0
  259. package/src/request/CommonDeviceCodeRequest.ts +31 -0
  260. package/src/request/CommonEndSessionRequest.ts +27 -0
  261. package/src/request/CommonOnBehalfOfRequest.ts +19 -0
  262. package/src/request/CommonRefreshTokenRequest.ts +25 -0
  263. package/src/request/CommonSilentFlowRequest.ts +24 -0
  264. package/src/request/CommonUsernamePasswordRequest.ts +23 -0
  265. package/src/request/NativeRequest.ts +25 -0
  266. package/src/request/NativeSignOutRequest.ts +10 -0
  267. package/src/request/RequestParameterBuilder.ts +606 -0
  268. package/src/request/RequestValidator.ts +103 -0
  269. package/src/request/ScopeSet.ts +230 -0
  270. package/src/request/StoreInCache.ts +16 -0
  271. package/src/response/AuthenticationResult.ts +47 -0
  272. package/src/response/AuthorizationCodePayload.ts +18 -0
  273. package/src/response/DeviceCodeResponse.ts +31 -0
  274. package/src/response/ExternalTokenResponse.ts +24 -0
  275. package/src/response/IMDSBadResponse.ts +9 -0
  276. package/src/response/ResponseHandler.ts +614 -0
  277. package/src/response/ServerAuthorizationCodeResponse.ts +33 -0
  278. package/src/response/ServerAuthorizationTokenResponse.ts +54 -0
  279. package/src/telemetry/performance/IPerformanceClient.ts +71 -0
  280. package/src/telemetry/performance/IPerformanceMeasurement.ts +10 -0
  281. package/src/telemetry/performance/PerformanceClient.ts +635 -0
  282. package/src/telemetry/performance/PerformanceEvent.ts +542 -0
  283. package/src/telemetry/performance/StubPerformanceClient.ts +101 -0
  284. package/src/telemetry/server/ServerTelemetryManager.ts +274 -0
  285. package/src/telemetry/server/ServerTelemetryRequest.ts +13 -0
  286. package/src/url/IUri.ts +17 -0
  287. package/src/url/UrlString.ts +363 -0
  288. package/src/utils/Constants.ts +436 -0
  289. package/src/utils/FunctionWrappers.ts +105 -0
  290. package/src/utils/MsalTypes.ts +9 -0
  291. package/src/utils/ProtocolUtils.ts +124 -0
  292. package/src/utils/StringUtils.ts +106 -0
  293. package/src/utils/TimeUtils.ts +51 -0
  294. package/dist/account/DecodedAuthToken.d.ts +0 -9
  295. package/dist/account/DecodedAuthToken.d.ts.map +0 -1
@@ -0,0 +1,230 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { ClientConfigurationError } from "../error/ClientConfigurationError";
7
+ import { StringUtils } from "../utils/StringUtils";
8
+ import { ClientAuthError } from "../error/ClientAuthError";
9
+ import { Constants, OIDC_SCOPES } from "../utils/Constants";
10
+
11
+ /**
12
+ * The ScopeSet class creates a set of scopes. Scopes are case-insensitive, unique values, so the Set object in JS makes
13
+ * the most sense to implement for this class. All scopes are trimmed and converted to lower case strings in intersection and union functions
14
+ * to ensure uniqueness of strings.
15
+ */
16
+ export class ScopeSet {
17
+ // Scopes as a Set of strings
18
+ private scopes: Set<string>;
19
+
20
+ constructor(inputScopes: Array<string>) {
21
+ // Filter empty string and null/undefined array items
22
+ const scopeArr = inputScopes
23
+ ? StringUtils.trimArrayEntries([...inputScopes])
24
+ : [];
25
+ const filteredInput = scopeArr
26
+ ? StringUtils.removeEmptyStringsFromArray(scopeArr)
27
+ : [];
28
+
29
+ // Validate and filter scopes (validate function throws if validation fails)
30
+ this.validateInputScopes(filteredInput);
31
+
32
+ this.scopes = new Set<string>(); // Iterator in constructor not supported by IE11
33
+ filteredInput.forEach((scope) => this.scopes.add(scope));
34
+ }
35
+
36
+ /**
37
+ * Factory method to create ScopeSet from space-delimited string
38
+ * @param inputScopeString
39
+ * @param appClientId
40
+ * @param scopesRequired
41
+ */
42
+ static fromString(inputScopeString: string): ScopeSet {
43
+ const scopeString = inputScopeString || Constants.EMPTY_STRING;
44
+ const inputScopes: Array<string> = scopeString.split(" ");
45
+ return new ScopeSet(inputScopes);
46
+ }
47
+
48
+ /**
49
+ * Creates the set of scopes to search for in cache lookups
50
+ * @param inputScopeString
51
+ * @returns
52
+ */
53
+ static createSearchScopes(inputScopeString: Array<string>): ScopeSet {
54
+ const scopeSet = new ScopeSet(inputScopeString);
55
+ if (!scopeSet.containsOnlyOIDCScopes()) {
56
+ scopeSet.removeOIDCScopes();
57
+ } else {
58
+ scopeSet.removeScope(Constants.OFFLINE_ACCESS_SCOPE);
59
+ }
60
+
61
+ return scopeSet;
62
+ }
63
+
64
+ /**
65
+ * Used to validate the scopes input parameter requested by the developer.
66
+ * @param {Array<string>} inputScopes - Developer requested permissions. Not all scopes are guaranteed to be included in the access token returned.
67
+ * @param {boolean} scopesRequired - Boolean indicating whether the scopes array is required or not
68
+ */
69
+ private validateInputScopes(inputScopes: Array<string>): void {
70
+ // Check if scopes are required but not given or is an empty array
71
+ if (!inputScopes || inputScopes.length < 1) {
72
+ throw ClientConfigurationError.createEmptyScopesArrayError();
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Check if a given scope is present in this set of scopes.
78
+ * @param scope
79
+ */
80
+ containsScope(scope: string): boolean {
81
+ const lowerCaseScopes = this.printScopesLowerCase().split(" ");
82
+ const lowerCaseScopesSet = new ScopeSet(lowerCaseScopes);
83
+ // compare lowercase scopes
84
+ return scope
85
+ ? lowerCaseScopesSet.scopes.has(scope.toLowerCase())
86
+ : false;
87
+ }
88
+
89
+ /**
90
+ * Check if a set of scopes is present in this set of scopes.
91
+ * @param scopeSet
92
+ */
93
+ containsScopeSet(scopeSet: ScopeSet): boolean {
94
+ if (!scopeSet || scopeSet.scopes.size <= 0) {
95
+ return false;
96
+ }
97
+
98
+ return (
99
+ this.scopes.size >= scopeSet.scopes.size &&
100
+ scopeSet.asArray().every((scope) => this.containsScope(scope))
101
+ );
102
+ }
103
+
104
+ /**
105
+ * Check if set of scopes contains only the defaults
106
+ */
107
+ containsOnlyOIDCScopes(): boolean {
108
+ let defaultScopeCount = 0;
109
+ OIDC_SCOPES.forEach((defaultScope: string) => {
110
+ if (this.containsScope(defaultScope)) {
111
+ defaultScopeCount += 1;
112
+ }
113
+ });
114
+
115
+ return this.scopes.size === defaultScopeCount;
116
+ }
117
+
118
+ /**
119
+ * Appends single scope if passed
120
+ * @param newScope
121
+ */
122
+ appendScope(newScope: string): void {
123
+ if (newScope) {
124
+ this.scopes.add(newScope.trim());
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Appends multiple scopes if passed
130
+ * @param newScopes
131
+ */
132
+ appendScopes(newScopes: Array<string>): void {
133
+ try {
134
+ newScopes.forEach((newScope) => this.appendScope(newScope));
135
+ } catch (e) {
136
+ throw ClientAuthError.createAppendScopeSetError(e as string);
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Removes element from set of scopes.
142
+ * @param scope
143
+ */
144
+ removeScope(scope: string): void {
145
+ if (!scope) {
146
+ throw ClientAuthError.createRemoveEmptyScopeFromSetError(scope);
147
+ }
148
+ this.scopes.delete(scope.trim());
149
+ }
150
+
151
+ /**
152
+ * Removes default scopes from set of scopes
153
+ * Primarily used to prevent cache misses if the default scopes are not returned from the server
154
+ */
155
+ removeOIDCScopes(): void {
156
+ OIDC_SCOPES.forEach((defaultScope: string) => {
157
+ this.scopes.delete(defaultScope);
158
+ });
159
+ }
160
+
161
+ /**
162
+ * Combines an array of scopes with the current set of scopes.
163
+ * @param otherScopes
164
+ */
165
+ unionScopeSets(otherScopes: ScopeSet): Set<string> {
166
+ if (!otherScopes) {
167
+ throw ClientAuthError.createEmptyInputScopeSetError();
168
+ }
169
+ const unionScopes = new Set<string>(); // Iterator in constructor not supported in IE11
170
+ otherScopes.scopes.forEach((scope) =>
171
+ unionScopes.add(scope.toLowerCase())
172
+ );
173
+ this.scopes.forEach((scope) => unionScopes.add(scope.toLowerCase()));
174
+ return unionScopes;
175
+ }
176
+
177
+ /**
178
+ * Check if scopes intersect between this set and another.
179
+ * @param otherScopes
180
+ */
181
+ intersectingScopeSets(otherScopes: ScopeSet): boolean {
182
+ if (!otherScopes) {
183
+ throw ClientAuthError.createEmptyInputScopeSetError();
184
+ }
185
+
186
+ // Do not allow OIDC scopes to be the only intersecting scopes
187
+ if (!otherScopes.containsOnlyOIDCScopes()) {
188
+ otherScopes.removeOIDCScopes();
189
+ }
190
+ const unionScopes = this.unionScopeSets(otherScopes);
191
+ const sizeOtherScopes = otherScopes.getScopeCount();
192
+ const sizeThisScopes = this.getScopeCount();
193
+ const sizeUnionScopes = unionScopes.size;
194
+ return sizeUnionScopes < sizeThisScopes + sizeOtherScopes;
195
+ }
196
+
197
+ /**
198
+ * Returns size of set of scopes.
199
+ */
200
+ getScopeCount(): number {
201
+ return this.scopes.size;
202
+ }
203
+
204
+ /**
205
+ * Returns the scopes as an array of string values
206
+ */
207
+ asArray(): Array<string> {
208
+ const array: Array<string> = [];
209
+ this.scopes.forEach((val) => array.push(val));
210
+ return array;
211
+ }
212
+
213
+ /**
214
+ * Prints scopes into a space-delimited string
215
+ */
216
+ printScopes(): string {
217
+ if (this.scopes) {
218
+ const scopeArr = this.asArray();
219
+ return scopeArr.join(" ");
220
+ }
221
+ return Constants.EMPTY_STRING;
222
+ }
223
+
224
+ /**
225
+ * Prints scopes into a space-delimited lower-case string (used for caching)
226
+ */
227
+ printScopesLowerCase(): string {
228
+ return this.printScopes().toLowerCase();
229
+ }
230
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /**
7
+ * Controls whether tokens should be stored in the cache or not. If set to false, tokens may still be acquired and returned but will not be cached for later retrieval.
8
+ */
9
+ export type StoreInCache = {
10
+ /* Indicates whether or not the acquired accessToken will be stored in the cache */
11
+ accessToken?: boolean;
12
+ /* Indicates whether or not the acquired idToken will be stored in the cache */
13
+ idToken?: boolean;
14
+ /* Indicates whether or not the acquired refreshToken will be stored in the cache */
15
+ refreshToken?: boolean;
16
+ };
@@ -0,0 +1,47 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { AccountInfo } from "../account/AccountInfo";
7
+
8
+ /**
9
+ * Result returned from the authority's token endpoint.
10
+ * - uniqueId - `oid` or `sub` claim from ID token
11
+ * - tenantId - `tid` claim from ID token
12
+ * - scopes - Scopes that are validated for the respective token
13
+ * - account - An account object representation of the currently signed-in user
14
+ * - idToken - Id token received as part of the response
15
+ * - idTokenClaims - MSAL-relevant ID token claims
16
+ * - accessToken - Access token or SSH certificate received as part of the response
17
+ * - fromCache - Boolean denoting whether token came from cache
18
+ * - expiresOn - Javascript Date object representing relative expiration of access token
19
+ * - extExpiresOn - Javascript Date object representing extended relative expiration of access token in case of server outage
20
+ * - refreshOn - Javascript Date object representing relative time until an access token must be refreshed
21
+ * - state - Value passed in by user in request
22
+ * - familyId - Family ID identifier, usually only used for refresh tokens
23
+ * - requestId - Request ID returned as part of the response
24
+ */
25
+ export type AuthenticationResult = {
26
+ authority: string;
27
+ uniqueId: string;
28
+ tenantId: string;
29
+ scopes: Array<string>;
30
+ account: AccountInfo | null;
31
+ idToken: string;
32
+ idTokenClaims: object;
33
+ accessToken: string;
34
+ fromCache: boolean;
35
+ expiresOn: Date | null;
36
+ extExpiresOn?: Date;
37
+ refreshOn?: Date;
38
+ tokenType: string;
39
+ correlationId: string;
40
+ requestId?: string;
41
+ state?: string;
42
+ familyId?: string;
43
+ cloudGraphHostName?: string;
44
+ msGraphHost?: string;
45
+ code?: string;
46
+ fromNativeBroker?: boolean;
47
+ };
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /**
7
+ * Response returned after processing the code response query string or fragment.
8
+ */
9
+ export type AuthorizationCodePayload = {
10
+ code: string;
11
+ cloud_instance_name?: string;
12
+ cloud_instance_host_name?: string;
13
+ cloud_graph_host_name?: string;
14
+ msgraph_host?: string;
15
+ state?: string;
16
+ nonce?: string;
17
+ client_info?: string;
18
+ };
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /**
7
+ * DeviceCode returned by the security token service device code endpoint containing information necessary for device code flow.
8
+ * - userCode: code which user needs to provide when authenticating at the verification URI
9
+ * - deviceCode: code which should be included in the request for the access token
10
+ * - verificationUri: URI where user can authenticate
11
+ * - expiresIn: expiration time of the device code in seconds
12
+ * - interval: interval at which the STS should be polled at
13
+ * - message: message which should be displayed to the user
14
+ */
15
+ export type DeviceCodeResponse = {
16
+ userCode: string;
17
+ deviceCode: string;
18
+ verificationUri: string;
19
+ expiresIn: number;
20
+ interval: number;
21
+ message: string;
22
+ };
23
+
24
+ export type ServerDeviceCodeResponse = {
25
+ user_code: string;
26
+ device_code: string;
27
+ verification_uri: string;
28
+ expires_in: number;
29
+ interval: number;
30
+ message: string;
31
+ };
@@ -0,0 +1,24 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { ServerAuthorizationTokenResponse } from "./ServerAuthorizationTokenResponse";
7
+
8
+ /**
9
+ * Response object used for loading external tokens to cache.
10
+ * - token_type: Indicates the token type value. The only type that Azure AD supports is Bearer.
11
+ * - scope: The scopes that the access_token is valid for.
12
+ * - expires_in: How long the access token is valid (in seconds).
13
+ * - id_token: A JSON Web Token (JWT). The app can decode the segments of this token to request information about the user who signed in.
14
+ * - refresh_token: An OAuth 2.0 refresh token. The app can use this token acquire additional access tokens after the current access token expires.
15
+ * - access_token: The requested access token. The app can use this token to authenticate to the secured resource, such as a web API.
16
+ * - client_info: Client info object
17
+ */
18
+ export type ExternalTokenResponse = Pick<
19
+ ServerAuthorizationTokenResponse,
20
+ "token_type" | "scope" | "expires_in" | "id_token" | "refresh_token"
21
+ > & {
22
+ access_token?: string;
23
+ client_info?: string;
24
+ };
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ export type IMDSBadResponse = {
7
+ error: string;
8
+ "newest-versions": Array<string>;
9
+ };