@azure/msal-browser 3.1.0 → 3.3.0

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 (282) hide show
  1. package/dist/app/IPublicClientApplication.d.ts.map +1 -1
  2. package/dist/app/IPublicClientApplication.mjs +20 -19
  3. package/dist/app/IPublicClientApplication.mjs.map +1 -1
  4. package/dist/app/PublicClientApplication.d.ts +14 -6
  5. package/dist/app/PublicClientApplication.d.ts.map +1 -1
  6. package/dist/app/PublicClientApplication.mjs +18 -8
  7. package/dist/app/PublicClientApplication.mjs.map +1 -1
  8. package/dist/app/PublicClientNext.d.ts +274 -0
  9. package/dist/app/PublicClientNext.d.ts.map +1 -0
  10. package/dist/app/PublicClientNext.mjs +362 -0
  11. package/dist/app/PublicClientNext.mjs.map +1 -0
  12. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts +3 -4
  13. package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -1
  14. package/dist/broker/nativeBroker/NativeMessageHandler.mjs +13 -13
  15. package/dist/broker/nativeBroker/NativeMessageHandler.mjs.map +1 -1
  16. package/dist/broker/nativeBroker/NativeStatusCodes.d.ts +8 -0
  17. package/dist/broker/nativeBroker/NativeStatusCodes.d.ts.map +1 -0
  18. package/dist/broker/nativeBroker/NativeStatusCodes.mjs +16 -0
  19. package/dist/broker/nativeBroker/NativeStatusCodes.mjs.map +1 -0
  20. package/dist/cache/AsyncMemoryStorage.mjs +1 -1
  21. package/dist/cache/BrowserCacheManager.d.ts +4 -15
  22. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  23. package/dist/cache/BrowserCacheManager.mjs +13 -69
  24. package/dist/cache/BrowserCacheManager.mjs.map +1 -1
  25. package/dist/cache/BrowserStorage.d.ts.map +1 -1
  26. package/dist/cache/BrowserStorage.mjs +7 -9
  27. package/dist/cache/BrowserStorage.mjs.map +1 -1
  28. package/dist/cache/CryptoKeyStore.mjs +1 -1
  29. package/dist/cache/DatabaseStorage.mjs +1 -1
  30. package/dist/cache/MemoryStorage.mjs +1 -1
  31. package/dist/cache/TokenCache.mjs +1 -1
  32. package/dist/config/Configuration.d.ts +4 -0
  33. package/dist/config/Configuration.d.ts.map +1 -1
  34. package/dist/config/Configuration.mjs +8 -7
  35. package/dist/config/Configuration.mjs.map +1 -1
  36. package/dist/controllers/ControllerFactory.d.ts +2 -1
  37. package/dist/controllers/ControllerFactory.d.ts.map +1 -1
  38. package/dist/controllers/ControllerFactory.mjs +26 -19
  39. package/dist/controllers/ControllerFactory.mjs.map +1 -1
  40. package/dist/controllers/IController.d.ts +3 -2
  41. package/dist/controllers/IController.d.ts.map +1 -1
  42. package/dist/controllers/NestedAppAuthController.d.ts +96 -0
  43. package/dist/controllers/NestedAppAuthController.d.ts.map +1 -0
  44. package/dist/controllers/NestedAppAuthController.mjs +345 -0
  45. package/dist/controllers/NestedAppAuthController.mjs.map +1 -0
  46. package/dist/controllers/StandardController.d.ts +11 -6
  47. package/dist/controllers/StandardController.d.ts.map +1 -1
  48. package/dist/controllers/StandardController.mjs +67 -45
  49. package/dist/controllers/StandardController.mjs.map +1 -1
  50. package/dist/controllers/UnknownOperatingContextController.d.ts +88 -0
  51. package/dist/controllers/UnknownOperatingContextController.d.ts.map +1 -0
  52. package/dist/controllers/UnknownOperatingContextController.mjs +275 -0
  53. package/dist/controllers/UnknownOperatingContextController.mjs.map +1 -0
  54. package/dist/crypto/BrowserCrypto.d.ts +44 -49
  55. package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
  56. package/dist/crypto/BrowserCrypto.mjs +77 -77
  57. package/dist/crypto/BrowserCrypto.mjs.map +1 -1
  58. package/dist/crypto/CryptoOps.d.ts +1 -7
  59. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  60. package/dist/crypto/CryptoOps.mjs +18 -23
  61. package/dist/crypto/CryptoOps.mjs.map +1 -1
  62. package/dist/crypto/PkceGenerator.d.ts +6 -21
  63. package/dist/crypto/PkceGenerator.d.ts.map +1 -1
  64. package/dist/crypto/PkceGenerator.mjs +45 -46
  65. package/dist/crypto/PkceGenerator.mjs.map +1 -1
  66. package/dist/crypto/SignedHttpRequest.mjs +1 -1
  67. package/dist/encode/Base64Decode.d.ts.map +1 -1
  68. package/dist/encode/Base64Decode.mjs +18 -2
  69. package/dist/encode/Base64Decode.mjs.map +1 -1
  70. package/dist/encode/Base64Encode.mjs +1 -1
  71. package/dist/error/BrowserAuthError.d.ts +10 -1
  72. package/dist/error/BrowserAuthError.d.ts.map +1 -1
  73. package/dist/error/BrowserAuthError.mjs +12 -3
  74. package/dist/error/BrowserAuthError.mjs.map +1 -1
  75. package/dist/error/BrowserAuthErrorCodes.d.ts +1 -0
  76. package/dist/error/BrowserAuthErrorCodes.d.ts.map +1 -1
  77. package/dist/error/BrowserAuthErrorCodes.mjs +3 -2
  78. package/dist/error/BrowserAuthErrorCodes.mjs.map +1 -1
  79. package/dist/error/BrowserConfigurationAuthError.d.ts +9 -46
  80. package/dist/error/BrowserConfigurationAuthError.d.ts.map +1 -1
  81. package/dist/error/BrowserConfigurationAuthError.mjs +20 -73
  82. package/dist/error/BrowserConfigurationAuthError.mjs.map +1 -1
  83. package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts +4 -0
  84. package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts.map +1 -0
  85. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +12 -0
  86. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs.map +1 -0
  87. package/dist/error/NativeAuthError.d.ts +17 -45
  88. package/dist/error/NativeAuthError.d.ts.map +1 -1
  89. package/dist/error/NativeAuthError.mjs +47 -78
  90. package/dist/error/NativeAuthError.mjs.map +1 -1
  91. package/dist/error/NativeAuthErrorCodes.d.ts +3 -0
  92. package/dist/error/NativeAuthErrorCodes.d.ts.map +1 -0
  93. package/dist/error/NativeAuthErrorCodes.mjs +11 -0
  94. package/dist/error/NativeAuthErrorCodes.mjs.map +1 -0
  95. package/dist/error/NestedAppAuthError.d.ts +15 -0
  96. package/dist/error/NestedAppAuthError.d.ts.map +1 -0
  97. package/dist/error/NestedAppAuthError.mjs +30 -0
  98. package/dist/error/NestedAppAuthError.mjs.map +1 -0
  99. package/dist/event/EventHandler.d.ts.map +1 -1
  100. package/dist/event/EventHandler.mjs +3 -2
  101. package/dist/event/EventHandler.mjs.map +1 -1
  102. package/dist/event/EventMessage.mjs +1 -1
  103. package/dist/event/EventType.mjs +1 -1
  104. package/dist/index.d.ts +5 -7
  105. package/dist/index.d.ts.map +1 -1
  106. package/dist/index.mjs +7 -3
  107. package/dist/index.mjs.map +1 -1
  108. package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
  109. package/dist/interaction_client/BaseInteractionClient.mjs +10 -11
  110. package/dist/interaction_client/BaseInteractionClient.mjs.map +1 -1
  111. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
  112. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  113. package/dist/interaction_client/NativeInteractionClient.mjs +26 -13
  114. package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
  115. package/dist/interaction_client/PopupClient.d.ts.map +1 -1
  116. package/dist/interaction_client/PopupClient.mjs +5 -4
  117. package/dist/interaction_client/PopupClient.mjs.map +1 -1
  118. package/dist/interaction_client/RedirectClient.mjs +7 -7
  119. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
  120. package/dist/interaction_client/SilentAuthCodeClient.mjs +7 -10
  121. package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
  122. package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
  123. package/dist/interaction_client/SilentCacheClient.mjs +11 -18
  124. package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
  125. package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
  126. package/dist/interaction_client/SilentIframeClient.mjs +27 -13
  127. package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
  128. package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
  129. package/dist/interaction_client/SilentRefreshClient.mjs +8 -18
  130. package/dist/interaction_client/SilentRefreshClient.mjs.map +1 -1
  131. package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
  132. package/dist/interaction_client/StandardInteractionClient.mjs +16 -37
  133. package/dist/interaction_client/StandardInteractionClient.mjs.map +1 -1
  134. package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
  135. package/dist/interaction_handler/InteractionHandler.mjs +6 -9
  136. package/dist/interaction_handler/InteractionHandler.mjs.map +1 -1
  137. package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
  138. package/dist/interaction_handler/RedirectHandler.mjs +3 -3
  139. package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
  140. package/dist/interaction_handler/SilentHandler.d.ts +13 -47
  141. package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
  142. package/dist/interaction_handler/SilentHandler.mjs +120 -156
  143. package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
  144. package/dist/naa/AccountInfo.d.ts +13 -0
  145. package/dist/naa/AccountInfo.d.ts.map +1 -0
  146. package/dist/naa/AccountRequests.d.ts +10 -0
  147. package/dist/naa/AccountRequests.d.ts.map +1 -0
  148. package/dist/naa/AuthBridge.d.ts +6 -0
  149. package/dist/naa/AuthBridge.d.ts.map +1 -0
  150. package/dist/naa/BridgeCapabilities.d.ts +4 -0
  151. package/dist/naa/BridgeCapabilities.d.ts.map +1 -0
  152. package/dist/naa/BridgeError.d.ts +10 -0
  153. package/dist/naa/BridgeError.d.ts.map +1 -0
  154. package/dist/naa/BridgeError.mjs +12 -0
  155. package/dist/naa/BridgeError.mjs.map +1 -0
  156. package/dist/naa/BridgeProxy.d.ts +72 -0
  157. package/dist/naa/BridgeProxy.d.ts.map +1 -0
  158. package/dist/naa/BridgeProxy.mjs +154 -0
  159. package/dist/naa/BridgeProxy.mjs.map +1 -0
  160. package/dist/naa/BridgeRequest.d.ts +7 -0
  161. package/dist/naa/BridgeRequest.d.ts.map +1 -0
  162. package/dist/naa/BridgeRequestEnvelope.d.ts +14 -0
  163. package/dist/naa/BridgeRequestEnvelope.d.ts.map +1 -0
  164. package/dist/naa/BridgeResponseEnvelope.d.ts +11 -0
  165. package/dist/naa/BridgeResponseEnvelope.d.ts.map +1 -0
  166. package/dist/naa/BridgeStatusCode.d.ts +11 -0
  167. package/dist/naa/BridgeStatusCode.d.ts.map +1 -0
  168. package/dist/naa/BridgeStatusCode.mjs +20 -0
  169. package/dist/naa/BridgeStatusCode.mjs.map +1 -0
  170. package/dist/naa/IBridgeProxy.d.ts +11 -0
  171. package/dist/naa/IBridgeProxy.d.ts.map +1 -0
  172. package/dist/naa/InitializeBridgeResponse.d.ts +7 -0
  173. package/dist/naa/InitializeBridgeResponse.d.ts.map +1 -0
  174. package/dist/naa/TokenRequest.d.ts +22 -0
  175. package/dist/naa/TokenRequest.d.ts.map +1 -0
  176. package/dist/naa/TokenResponse.d.ts +17 -0
  177. package/dist/naa/TokenResponse.d.ts.map +1 -0
  178. package/dist/naa/mapping/NestedAppAuthAdapter.d.ts +26 -0
  179. package/dist/naa/mapping/NestedAppAuthAdapter.d.ts.map +1 -0
  180. package/dist/naa/mapping/NestedAppAuthAdapter.mjs +178 -0
  181. package/dist/naa/mapping/NestedAppAuthAdapter.mjs.map +1 -0
  182. package/dist/navigation/NavigationClient.mjs +1 -1
  183. package/dist/network/FetchClient.mjs +1 -1
  184. package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
  185. package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
  186. package/dist/operatingcontext/TeamsAppOperatingContext.d.ts +7 -0
  187. package/dist/operatingcontext/TeamsAppOperatingContext.d.ts.map +1 -1
  188. package/dist/operatingcontext/TeamsAppOperatingContext.mjs +45 -4
  189. package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +1 -1
  190. package/dist/operatingcontext/UnknownOperatingContext.d.ts +26 -0
  191. package/dist/operatingcontext/UnknownOperatingContext.d.ts.map +1 -0
  192. package/dist/operatingcontext/UnknownOperatingContext.mjs +49 -0
  193. package/dist/operatingcontext/UnknownOperatingContext.mjs.map +1 -0
  194. package/dist/packageMetadata.d.ts +1 -1
  195. package/dist/packageMetadata.mjs +2 -2
  196. package/dist/telemetry/BrowserPerformanceClient.mjs +1 -1
  197. package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
  198. package/dist/utils/BrowserConstants.mjs +1 -1
  199. package/dist/utils/BrowserProtocolUtils.d.ts.map +1 -1
  200. package/dist/utils/BrowserProtocolUtils.mjs +3 -3
  201. package/dist/utils/BrowserProtocolUtils.mjs.map +1 -1
  202. package/dist/utils/BrowserUtils.d.ts +54 -53
  203. package/dist/utils/BrowserUtils.d.ts.map +1 -1
  204. package/dist/utils/BrowserUtils.mjs +114 -102
  205. package/dist/utils/BrowserUtils.mjs.map +1 -1
  206. package/lib/msal-browser.cjs +61 -18042
  207. package/lib/msal-browser.cjs.map +1 -1
  208. package/lib/msal-browser.js +13593 -12505
  209. package/lib/msal-browser.js.map +1 -1
  210. package/lib/msal-browser.min.js +66 -65
  211. package/package.json +2 -2
  212. package/src/app/IPublicClientApplication.ts +55 -18
  213. package/src/app/PublicClientApplication.ts +19 -7
  214. package/src/app/PublicClientNext.ts +442 -0
  215. package/src/broker/nativeBroker/NativeMessageHandler.ts +12 -15
  216. package/src/broker/nativeBroker/NativeStatusCodes.ts +13 -0
  217. package/src/cache/BrowserCacheManager.ts +29 -103
  218. package/src/cache/BrowserStorage.ts +9 -11
  219. package/src/config/Configuration.ts +21 -8
  220. package/src/controllers/ControllerFactory.ts +36 -25
  221. package/src/controllers/IController.ts +4 -1
  222. package/src/controllers/NestedAppAuthController.ts +525 -0
  223. package/src/controllers/StandardController.ts +163 -98
  224. package/src/controllers/UnknownOperatingContextController.ts +383 -0
  225. package/src/crypto/BrowserCrypto.ts +119 -103
  226. package/src/crypto/CryptoOps.ts +18 -27
  227. package/src/crypto/PkceGenerator.ts +93 -54
  228. package/src/encode/Base64Decode.ts +21 -1
  229. package/src/error/BrowserAuthError.ts +13 -1
  230. package/src/error/BrowserAuthErrorCodes.ts +1 -0
  231. package/src/error/BrowserConfigurationAuthError.ts +33 -102
  232. package/src/error/BrowserConfigurationAuthErrorCodes.ts +9 -0
  233. package/src/error/NativeAuthError.ts +73 -101
  234. package/src/error/NativeAuthErrorCodes.ts +7 -0
  235. package/src/error/NestedAppAuthError.ts +32 -0
  236. package/src/event/EventHandler.ts +2 -1
  237. package/src/index.ts +8 -10
  238. package/src/interaction_client/BaseInteractionClient.ts +14 -8
  239. package/src/interaction_client/NativeInteractionClient.ts +48 -14
  240. package/src/interaction_client/PopupClient.ts +2 -1
  241. package/src/interaction_client/RedirectClient.ts +1 -1
  242. package/src/interaction_client/SilentAuthCodeClient.ts +22 -19
  243. package/src/interaction_client/SilentCacheClient.ts +28 -28
  244. package/src/interaction_client/SilentIframeClient.ts +54 -18
  245. package/src/interaction_client/SilentRefreshClient.ts +26 -28
  246. package/src/interaction_client/StandardInteractionClient.ts +37 -68
  247. package/src/interaction_handler/InteractionHandler.ts +20 -15
  248. package/src/interaction_handler/RedirectHandler.ts +6 -2
  249. package/src/interaction_handler/SilentHandler.ts +177 -230
  250. package/src/naa/AccountInfo.ts +17 -0
  251. package/src/naa/AccountRequests.ts +16 -0
  252. package/src/naa/AuthBridge.ts +16 -0
  253. package/src/naa/BridgeCapabilities.ts +8 -0
  254. package/src/naa/BridgeError.ts +18 -0
  255. package/src/naa/BridgeProxy.ts +230 -0
  256. package/src/naa/BridgeRequest.ts +12 -0
  257. package/src/naa/BridgeRequestEnvelope.ts +46 -0
  258. package/src/naa/BridgeResponseEnvelope.ts +21 -0
  259. package/src/naa/BridgeStatusCode.ts +15 -0
  260. package/src/naa/IBridgeProxy.ts +25 -0
  261. package/src/naa/InitializeBridgeResponse.ts +12 -0
  262. package/src/naa/TokenRequest.ts +26 -0
  263. package/src/naa/TokenResponse.ts +61 -0
  264. package/src/naa/mapping/NestedAppAuthAdapter.ts +252 -0
  265. package/src/operatingcontext/TeamsAppOperatingContext.ts +43 -3
  266. package/src/operatingcontext/UnknownOperatingContext.ts +48 -0
  267. package/src/packageMetadata.ts +1 -1
  268. package/src/utils/BrowserProtocolUtils.ts +3 -2
  269. package/src/utils/BrowserUtils.ts +133 -125
  270. package/dist/crypto/ISubtleCrypto.d.ts +0 -10
  271. package/dist/crypto/ISubtleCrypto.d.ts.map +0 -1
  272. package/dist/crypto/ModernBrowserCrypto.d.ts +0 -10
  273. package/dist/crypto/ModernBrowserCrypto.d.ts.map +0 -1
  274. package/dist/crypto/ModernBrowserCrypto.mjs +0 -31
  275. package/dist/crypto/ModernBrowserCrypto.mjs.map +0 -1
  276. package/dist/utils/BrowserStringUtils.d.ts +0 -22
  277. package/dist/utils/BrowserStringUtils.d.ts.map +0 -1
  278. package/dist/utils/BrowserStringUtils.mjs +0 -144
  279. package/dist/utils/BrowserStringUtils.mjs.map +0 -1
  280. package/src/crypto/ISubtleCrypto.ts +0 -30
  281. package/src/crypto/ModernBrowserCrypto.ts +0 -69
  282. package/src/utils/BrowserStringUtils.ts +0 -143
@@ -9,15 +9,12 @@ import {
9
9
  JoseHeader,
10
10
  Logger,
11
11
  PerformanceEvents,
12
- PkceCodes,
13
12
  SignedHttpRequest,
14
13
  SignedHttpRequestParameters,
15
14
  } from "@azure/msal-common";
16
15
  import { base64Encode, urlEncode, urlEncodeArr } from "../encode/Base64Encode";
17
16
  import { base64Decode } from "../encode/Base64Decode";
18
- import { PkceGenerator } from "./PkceGenerator";
19
- import { BrowserCrypto } from "./BrowserCrypto";
20
- import { BrowserStringUtils } from "../utils/BrowserStringUtils";
17
+ import * as BrowserCrypto from "./BrowserCrypto";
21
18
  import {
22
19
  createBrowserAuthError,
23
20
  BrowserAuthErrorCodes,
@@ -36,8 +33,6 @@ export type CachedKeyPair = {
36
33
  * implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).
37
34
  */
38
35
  export class CryptoOps implements ICrypto {
39
- private browserCrypto: BrowserCrypto;
40
- private pkceGenerator: PkceGenerator;
41
36
  private logger: Logger;
42
37
 
43
38
  /**
@@ -53,8 +48,7 @@ export class CryptoOps implements ICrypto {
53
48
  constructor(logger: Logger, performanceClient?: IPerformanceClient) {
54
49
  this.logger = logger;
55
50
  // Browser crypto needs to be validated first before any other classes can be set.
56
- this.browserCrypto = new BrowserCrypto(this.logger);
57
- this.pkceGenerator = new PkceGenerator(this.browserCrypto);
51
+ BrowserCrypto.validateCryptoAvailable(logger);
58
52
  this.cache = new CryptoKeyStore(this.logger);
59
53
  this.performanceClient = performanceClient;
60
54
  }
@@ -64,7 +58,7 @@ export class CryptoOps implements ICrypto {
64
58
  * @returns string (GUID)
65
59
  */
66
60
  createNewGuid(): string {
67
- return window.crypto.randomUUID();
61
+ return BrowserCrypto.createNewGuid();
68
62
  }
69
63
 
70
64
  /**
@@ -83,13 +77,6 @@ export class CryptoOps implements ICrypto {
83
77
  return base64Decode(input);
84
78
  }
85
79
 
86
- /**
87
- * Generates PKCE codes used in Authorization Code Flow.
88
- */
89
- async generatePkceCodes(): Promise<PkceCodes> {
90
- return this.pkceGenerator.generateCodes();
91
- }
92
-
93
80
  /**
94
81
  * Generates a keypair, stores it and returns a thumbprint
95
82
  * @param request
@@ -104,13 +91,13 @@ export class CryptoOps implements ICrypto {
104
91
  );
105
92
 
106
93
  // Generate Keypair
107
- const keyPair: CryptoKeyPair = await this.browserCrypto.generateKeyPair(
94
+ const keyPair: CryptoKeyPair = await BrowserCrypto.generateKeyPair(
108
95
  CryptoOps.EXTRACTABLE,
109
96
  CryptoOps.POP_KEY_USAGES
110
97
  );
111
98
 
112
99
  // Generate Thumbprint for Public Key
113
- const publicKeyJwk: JsonWebKey = await this.browserCrypto.exportJwk(
100
+ const publicKeyJwk: JsonWebKey = await BrowserCrypto.exportJwk(
114
101
  keyPair.publicKey
115
102
  );
116
103
 
@@ -121,16 +108,16 @@ export class CryptoOps implements ICrypto {
121
108
  };
122
109
 
123
110
  const publicJwkString: string =
124
- BrowserStringUtils.getSortedObjectString(pubKeyThumprintObj);
111
+ getSortedObjectString(pubKeyThumprintObj);
125
112
  const publicJwkHash = await this.hashString(publicJwkString);
126
113
 
127
114
  // Generate Thumbprint for Private Key
128
- const privateKeyJwk: JsonWebKey = await this.browserCrypto.exportJwk(
115
+ const privateKeyJwk: JsonWebKey = await BrowserCrypto.exportJwk(
129
116
  keyPair.privateKey
130
117
  );
131
118
  // Re-import private key to make it unextractable
132
119
  const unextractablePrivateKey: CryptoKey =
133
- await this.browserCrypto.importJwk(privateKeyJwk, false, ["sign"]);
120
+ await BrowserCrypto.importJwk(privateKeyJwk, false, ["sign"]);
134
121
 
135
122
  // Store Keypair data in keystore
136
123
  await this.cache.asymmetricKeys.setItem(publicJwkHash, {
@@ -189,11 +176,10 @@ export class CryptoOps implements ICrypto {
189
176
  }
190
177
 
191
178
  // Get public key as JWK
192
- const publicKeyJwk = await this.browserCrypto.exportJwk(
179
+ const publicKeyJwk = await BrowserCrypto.exportJwk(
193
180
  cachedKeyPair.publicKey
194
181
  );
195
- const publicKeyJwkString =
196
- BrowserStringUtils.getSortedObjectString(publicKeyJwk);
182
+ const publicKeyJwkString = getSortedObjectString(publicKeyJwk);
197
183
 
198
184
  // Base64URL encode public key thumbprint with keyId only: BASE64URL({ kid: "FULL_PUBLIC_KEY_HASH" })
199
185
  const encodedKeyIdThumbprint = urlEncode(JSON.stringify({ kid: kid }));
@@ -215,8 +201,9 @@ export class CryptoOps implements ICrypto {
215
201
  const tokenString = `${encodedShrHeader}.${encodedPayload}`;
216
202
 
217
203
  // Sign token
218
- const tokenBuffer = BrowserStringUtils.stringToUtf8Arr(tokenString);
219
- const signatureBuffer = await this.browserCrypto.sign(
204
+ const encoder = new TextEncoder();
205
+ const tokenBuffer = encoder.encode(tokenString);
206
+ const signatureBuffer = await BrowserCrypto.sign(
220
207
  cachedKeyPair.privateKey,
221
208
  tokenBuffer
222
209
  );
@@ -238,10 +225,14 @@ export class CryptoOps implements ICrypto {
238
225
  * @param plainText
239
226
  */
240
227
  async hashString(plainText: string): Promise<string> {
241
- const hashBuffer: ArrayBuffer = await this.browserCrypto.sha256Digest(
228
+ const hashBuffer: ArrayBuffer = await BrowserCrypto.sha256Digest(
242
229
  plainText
243
230
  );
244
231
  const hashBytes = new Uint8Array(hashBuffer);
245
232
  return urlEncodeArr(hashBytes);
246
233
  }
247
234
  }
235
+
236
+ function getSortedObjectString(obj: object): string {
237
+ return JSON.stringify(obj, Object.keys(obj).sort());
238
+ }
@@ -3,74 +3,113 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { PkceCodes } from "@azure/msal-common";
6
+ import {
7
+ IPerformanceClient,
8
+ Logger,
9
+ PerformanceEvents,
10
+ PkceCodes,
11
+ invoke,
12
+ invokeAsync,
13
+ } from "@azure/msal-common";
7
14
  import {
8
15
  createBrowserAuthError,
9
16
  BrowserAuthErrorCodes,
10
17
  } from "../error/BrowserAuthError";
11
18
  import { urlEncodeArr } from "../encode/Base64Encode";
12
- import { BrowserCrypto } from "./BrowserCrypto";
19
+ import { getRandomValues, sha256Digest } from "./BrowserCrypto";
13
20
 
14
21
  // Constant byte array length
15
22
  const RANDOM_BYTE_ARR_LENGTH = 32;
16
23
 
17
24
  /**
18
- * Class which exposes APIs to generate PKCE codes and code verifiers.
25
+ * This file defines APIs to generate PKCE codes and code verifiers.
19
26
  */
20
- export class PkceGenerator {
21
- private cryptoObj: BrowserCrypto;
22
-
23
- constructor(cryptoObj: BrowserCrypto) {
24
- this.cryptoObj = cryptoObj;
25
- }
26
27
 
27
- /**
28
- * Generates PKCE Codes. See the RFC for more information: https://tools.ietf.org/html/rfc7636
29
- */
30
- async generateCodes(): Promise<PkceCodes> {
31
- const codeVerifier = this.generateCodeVerifier();
32
- const codeChallenge = await this.generateCodeChallengeFromVerifier(
33
- codeVerifier
34
- );
35
- return {
36
- verifier: codeVerifier,
37
- challenge: codeChallenge,
38
- };
39
- }
28
+ /**
29
+ * Generates PKCE Codes. See the RFC for more information: https://tools.ietf.org/html/rfc7636
30
+ */
31
+ export async function generatePkceCodes(
32
+ performanceClient: IPerformanceClient,
33
+ logger: Logger,
34
+ correlationId: string
35
+ ): Promise<PkceCodes> {
36
+ performanceClient.addQueueMeasurement(
37
+ PerformanceEvents.GeneratePkceCodes,
38
+ correlationId
39
+ );
40
+ const codeVerifier = invoke(
41
+ generateCodeVerifier,
42
+ PerformanceEvents.GenerateCodeVerifier,
43
+ logger,
44
+ performanceClient,
45
+ correlationId
46
+ )(performanceClient, logger, correlationId);
47
+ const codeChallenge = await invokeAsync(
48
+ generateCodeChallengeFromVerifier,
49
+ PerformanceEvents.GenerateCodeChallengeFromVerifier,
50
+ logger,
51
+ performanceClient,
52
+ correlationId
53
+ )(codeVerifier, performanceClient, logger, correlationId);
54
+ return {
55
+ verifier: codeVerifier,
56
+ challenge: codeChallenge,
57
+ };
58
+ }
40
59
 
41
- /**
42
- * Generates a random 32 byte buffer and returns the base64
43
- * encoded string to be used as a PKCE Code Verifier
44
- */
45
- private generateCodeVerifier(): string {
46
- try {
47
- // Generate random values as utf-8
48
- const buffer: Uint8Array = new Uint8Array(RANDOM_BYTE_ARR_LENGTH);
49
- this.cryptoObj.getRandomValues(buffer);
50
- // encode verifier as base64
51
- const pkceCodeVerifierB64: string = urlEncodeArr(buffer);
52
- return pkceCodeVerifierB64;
53
- } catch (e) {
54
- throw createBrowserAuthError(BrowserAuthErrorCodes.pkceNotCreated);
55
- }
60
+ /**
61
+ * Generates a random 32 byte buffer and returns the base64
62
+ * encoded string to be used as a PKCE Code Verifier
63
+ */
64
+ function generateCodeVerifier(
65
+ performanceClient: IPerformanceClient,
66
+ logger: Logger,
67
+ correlationId: string
68
+ ): string {
69
+ try {
70
+ // Generate random values as utf-8
71
+ const buffer: Uint8Array = new Uint8Array(RANDOM_BYTE_ARR_LENGTH);
72
+ invoke(
73
+ getRandomValues,
74
+ PerformanceEvents.GetRandomValues,
75
+ logger,
76
+ performanceClient,
77
+ correlationId
78
+ )(buffer);
79
+ // encode verifier as base64
80
+ const pkceCodeVerifierB64: string = urlEncodeArr(buffer);
81
+ return pkceCodeVerifierB64;
82
+ } catch (e) {
83
+ throw createBrowserAuthError(BrowserAuthErrorCodes.pkceNotCreated);
56
84
  }
85
+ }
57
86
 
58
- /**
59
- * Creates a base64 encoded PKCE Code Challenge string from the
60
- * hash created from the PKCE Code Verifier supplied
61
- */
62
- private async generateCodeChallengeFromVerifier(
63
- pkceCodeVerifier: string
64
- ): Promise<string> {
65
- try {
66
- // hashed verifier
67
- const pkceHashedCodeVerifier = await this.cryptoObj.sha256Digest(
68
- pkceCodeVerifier
69
- );
70
- // encode hash as base64
71
- return urlEncodeArr(new Uint8Array(pkceHashedCodeVerifier));
72
- } catch (e) {
73
- throw createBrowserAuthError(BrowserAuthErrorCodes.pkceNotCreated);
74
- }
87
+ /**
88
+ * Creates a base64 encoded PKCE Code Challenge string from the
89
+ * hash created from the PKCE Code Verifier supplied
90
+ */
91
+ async function generateCodeChallengeFromVerifier(
92
+ pkceCodeVerifier: string,
93
+ performanceClient: IPerformanceClient,
94
+ logger: Logger,
95
+ correlationId: string
96
+ ): Promise<string> {
97
+ performanceClient.addQueueMeasurement(
98
+ PerformanceEvents.GenerateCodeChallengeFromVerifier,
99
+ correlationId
100
+ );
101
+ try {
102
+ // hashed verifier
103
+ const pkceHashedCodeVerifier = await invokeAsync(
104
+ sha256Digest,
105
+ PerformanceEvents.Sha256Digest,
106
+ logger,
107
+ performanceClient,
108
+ correlationId
109
+ )(pkceCodeVerifier, performanceClient, correlationId);
110
+ // encode hash as base64
111
+ return urlEncodeArr(new Uint8Array(pkceHashedCodeVerifier));
112
+ } catch (e) {
113
+ throw createBrowserAuthError(BrowserAuthErrorCodes.pkceNotCreated);
75
114
  }
76
115
  }
@@ -3,6 +3,11 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ import {
7
+ BrowserAuthErrorCodes,
8
+ createBrowserAuthError,
9
+ } from "../error/BrowserAuthError";
10
+
6
11
  /**
7
12
  * Class which exposes APIs to decode base64 strings to plaintext. See here for implementation details:
8
13
  * https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
@@ -21,6 +26,21 @@ export function base64Decode(input: string): string {
21
26
  * @param base64String
22
27
  */
23
28
  function base64DecToArr(base64String: string): Uint8Array {
24
- const binString = atob(base64String);
29
+ let encodedString = base64String.replace(/-/g, "+").replace(/_/g, "/");
30
+ switch (encodedString.length % 4) {
31
+ case 0:
32
+ break;
33
+ case 2:
34
+ encodedString += "==";
35
+ break;
36
+ case 3:
37
+ encodedString += "=";
38
+ break;
39
+ default:
40
+ throw createBrowserAuthError(
41
+ BrowserAuthErrorCodes.invalidBase64String
42
+ );
43
+ }
44
+ const binString = atob(encodedString);
25
45
  return Uint8Array.from(binString, (m) => m.codePointAt(0) || 0);
26
46
  }
@@ -88,11 +88,17 @@ export const BrowserAuthErrorMessages = {
88
88
  [BrowserAuthErrorCodes.uninitializedPublicClientApplication]: `You must call and await the initialize function before attempting to call any other MSAL API. ${ErrorLink}`,
89
89
  [BrowserAuthErrorCodes.nativePromptNotSupported]:
90
90
  "The provided prompt is not supported by the native platform. This request should be routed to the web based flow.",
91
+ [BrowserAuthErrorCodes.invalidBase64String]:
92
+ "Invalid base64 encoded string.",
91
93
  };
92
94
 
93
95
  /**
94
96
  * BrowserAuthErrorMessage class containing string constants used by error codes and messages.
95
- * @deprecated Use BrowserAuthBrowserAuthErrorCodes instead
97
+ * @deprecated Use exported BrowserAuthErrorCodes instead.
98
+ * In your app you can do :
99
+ * ```
100
+ * import { BrowserAuthErrorCodes } from "@azure/msal-browser";
101
+ * ```
96
102
  */
97
103
  export const BrowserAuthErrorMessage = {
98
104
  pkceNotGenerated: {
@@ -321,6 +327,12 @@ export const BrowserAuthErrorMessage = {
321
327
  BrowserAuthErrorCodes.nativePromptNotSupported
322
328
  ],
323
329
  },
330
+ invalidBase64StringError: {
331
+ code: BrowserAuthErrorCodes.invalidBase64String,
332
+ desc: BrowserAuthErrorMessages[
333
+ BrowserAuthErrorCodes.invalidBase64String
334
+ ],
335
+ },
324
336
  };
325
337
 
326
338
  /**
@@ -54,3 +54,4 @@ export const nativeConnectionNotEstablished =
54
54
  export const uninitializedPublicClientApplication =
55
55
  "uninitialized_public_client_application";
56
56
  export const nativePromptNotSupported = "native_prompt_not_supported";
57
+ export const invalidBase64String = "invalid_base64_string";
@@ -4,46 +4,41 @@
4
4
  */
5
5
 
6
6
  import { AuthError } from "@azure/msal-common";
7
+ import * as BrowserConfigurationAuthErrorCodes from "./BrowserConfigurationAuthErrorCodes";
8
+ export { BrowserConfigurationAuthErrorCodes };
9
+
10
+ export const BrowserConfigurationAuthErrorMessages = {
11
+ [BrowserConfigurationAuthErrorCodes.storageNotSupported]:
12
+ "Given storage configuration option was not supported.",
13
+ [BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled]:
14
+ "Stub instance of Public Client Application was called. If using msal-react, please ensure context is not used without a provider. For more visit: aka.ms/msaljs/browser-errors",
15
+ [BrowserConfigurationAuthErrorCodes.inMemRedirectUnavailable]:
16
+ "Redirect cannot be supported. In-memory storage was selected and storeAuthStateInCookie=false, which would cause the library to be unable to handle the incoming hash. If you would like to use the redirect API, please use session/localStorage or set storeAuthStateInCookie=true.",
17
+ };
7
18
 
8
19
  /**
9
20
  * BrowserAuthErrorMessage class containing string constants used by error codes and messages.
21
+ * @deprecated Use BrowserAuthErrorCodes instead
10
22
  */
11
23
  export const BrowserConfigurationAuthErrorMessage = {
12
- redirectUriNotSet: {
13
- code: "redirect_uri_empty",
14
- desc: "A redirect URI is required for all calls, and none has been set.",
15
- },
16
- postLogoutUriNotSet: {
17
- code: "post_logout_uri_empty",
18
- desc: "A post logout redirect has not been set.",
19
- },
20
24
  storageNotSupportedError: {
21
- code: "storage_not_supported",
22
- desc: "Given storage configuration option was not supported.",
23
- },
24
- noRedirectCallbacksSet: {
25
- code: "no_redirect_callbacks",
26
- desc:
27
- "No redirect callbacks have been set. Please call setRedirectCallbacks() with the appropriate function arguments before continuing. " +
28
- "More information is available here: https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics.",
29
- },
30
- invalidCallbackObject: {
31
- code: "invalid_callback_object",
32
- desc:
33
- "The object passed for the callback was invalid. " +
34
- "More information is available here: https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics.",
25
+ code: BrowserConfigurationAuthErrorCodes.storageNotSupported,
26
+ desc: BrowserConfigurationAuthErrorMessages[
27
+ BrowserConfigurationAuthErrorCodes.storageNotSupported
28
+ ],
35
29
  },
36
30
  stubPcaInstanceCalled: {
37
- code: "stubbed_public_client_application_called",
38
- desc: "Stub instance of Public Client Application was called. If using msal-react, please ensure context is not used without a provider. For more visit: aka.ms/msaljs/browser-errors",
31
+ code: BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled,
32
+ desc: BrowserConfigurationAuthErrorMessages[
33
+ BrowserConfigurationAuthErrorCodes
34
+ .stubbedPublicClientApplicationCalled
35
+ ],
39
36
  },
40
37
  inMemRedirectUnavailable: {
41
- code: "in_mem_redirect_unavailable",
42
- desc: "Redirect cannot be supported. In-memory storage was selected and storeAuthStateInCookie=false, which would cause the library to be unable to handle the incoming hash. If you would like to use the redirect API, please use session/localStorage or set storeAuthStateInCookie=true.",
43
- },
44
- entropyNotProvided: {
45
- code: "entropy_not_provided",
46
- desc: "The available browser crypto interface requires entropy set via system.cryptoOptions.entropy configuration option.",
38
+ code: BrowserConfigurationAuthErrorCodes.inMemRedirectUnavailable,
39
+ desc: BrowserConfigurationAuthErrorMessages[
40
+ BrowserConfigurationAuthErrorCodes.inMemRedirectUnavailable
41
+ ],
47
42
  },
48
43
  };
49
44
 
@@ -57,77 +52,13 @@ export class BrowserConfigurationAuthError extends AuthError {
57
52
 
58
53
  Object.setPrototypeOf(this, BrowserConfigurationAuthError.prototype);
59
54
  }
55
+ }
60
56
 
61
- /**
62
- * Creates an error thrown when the redirect uri is empty (not set by caller)
63
- */
64
- static createRedirectUriEmptyError(): BrowserConfigurationAuthError {
65
- return new BrowserConfigurationAuthError(
66
- BrowserConfigurationAuthErrorMessage.redirectUriNotSet.code,
67
- BrowserConfigurationAuthErrorMessage.redirectUriNotSet.desc
68
- );
69
- }
70
-
71
- /**
72
- * Creates an error thrown when the post-logout redirect uri is empty (not set by caller)
73
- */
74
- static createPostLogoutRedirectUriEmptyError(): BrowserConfigurationAuthError {
75
- return new BrowserConfigurationAuthError(
76
- BrowserConfigurationAuthErrorMessage.postLogoutUriNotSet.code,
77
- BrowserConfigurationAuthErrorMessage.postLogoutUriNotSet.desc
78
- );
79
- }
80
-
81
- /**
82
- * Creates error thrown when given storage location is not supported.
83
- * @param givenStorageLocation
84
- */
85
- static createStorageNotSupportedError(
86
- givenStorageLocation: string
87
- ): BrowserConfigurationAuthError {
88
- return new BrowserConfigurationAuthError(
89
- BrowserConfigurationAuthErrorMessage.storageNotSupportedError.code,
90
- `${BrowserConfigurationAuthErrorMessage.storageNotSupportedError.desc} Given Location: ${givenStorageLocation}`
91
- );
92
- }
93
-
94
- /**
95
- * Creates error thrown when redirect callbacks are not set before calling loginRedirect() or acquireTokenRedirect().
96
- */
97
- static createRedirectCallbacksNotSetError(): BrowserConfigurationAuthError {
98
- return new BrowserConfigurationAuthError(
99
- BrowserConfigurationAuthErrorMessage.noRedirectCallbacksSet.code,
100
- BrowserConfigurationAuthErrorMessage.noRedirectCallbacksSet.desc
101
- );
102
- }
103
-
104
- /**
105
- * Creates error thrown when the stub instance of PublicClientApplication is called.
106
- */
107
- static createStubPcaInstanceCalledError(): BrowserConfigurationAuthError {
108
- return new BrowserConfigurationAuthError(
109
- BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.code,
110
- BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.desc
111
- );
112
- }
113
-
114
- /*
115
- * Create an error thrown when in-memory storage is used and storeAuthStateInCookie=false.
116
- */
117
- static createInMemoryRedirectUnavailableError(): BrowserConfigurationAuthError {
118
- return new BrowserConfigurationAuthError(
119
- BrowserConfigurationAuthErrorMessage.inMemRedirectUnavailable.code,
120
- BrowserConfigurationAuthErrorMessage.inMemRedirectUnavailable.desc
121
- );
122
- }
123
-
124
- /**
125
- * Creates an error thrown when a crypto interface that requires entropy is initialized without entropy
126
- */
127
- static createEntropyNotProvided(): BrowserConfigurationAuthError {
128
- return new BrowserConfigurationAuthError(
129
- BrowserConfigurationAuthErrorMessage.entropyNotProvided.code,
130
- BrowserConfigurationAuthErrorMessage.entropyNotProvided.desc
131
- );
132
- }
57
+ export function createBrowserConfigurationAuthError(
58
+ errorCode: string
59
+ ): BrowserConfigurationAuthError {
60
+ return new BrowserConfigurationAuthError(
61
+ errorCode,
62
+ BrowserConfigurationAuthErrorMessages[errorCode]
63
+ );
133
64
  }
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ export const storageNotSupported = "storage_not_supported";
7
+ export const stubbedPublicClientApplicationCalled =
8
+ "stubbed_public_client_application_called";
9
+ export const inMemRedirectUnavailable = "in_mem_redirect_unavailable";