@azure/msal-browser 3.6.0 → 3.7.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 (139) hide show
  1. package/dist/app/IPublicClientApplication.mjs +1 -1
  2. package/dist/app/PublicClientApplication.mjs +1 -1
  3. package/dist/app/PublicClientNext.mjs +1 -1
  4. package/dist/broker/nativeBroker/NativeMessageHandler.mjs +1 -1
  5. package/dist/broker/nativeBroker/NativeStatusCodes.mjs +1 -1
  6. package/dist/cache/AsyncMemoryStorage.mjs +1 -1
  7. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  8. package/dist/cache/BrowserCacheManager.mjs +9 -9
  9. package/dist/cache/BrowserCacheManager.mjs.map +1 -1
  10. package/dist/cache/BrowserStorage.mjs +1 -1
  11. package/dist/cache/CryptoKeyStore.mjs +1 -1
  12. package/dist/cache/DatabaseStorage.mjs +1 -1
  13. package/dist/cache/MemoryStorage.mjs +1 -1
  14. package/dist/cache/TokenCache.d.ts.map +1 -1
  15. package/dist/cache/TokenCache.mjs +4 -2
  16. package/dist/cache/TokenCache.mjs.map +1 -1
  17. package/dist/config/Configuration.mjs +1 -1
  18. package/dist/controllers/ControllerFactory.mjs +1 -1
  19. package/dist/controllers/NestedAppAuthController.mjs +1 -1
  20. package/dist/controllers/StandardController.d.ts.map +1 -1
  21. package/dist/controllers/StandardController.mjs +32 -17
  22. package/dist/controllers/StandardController.mjs.map +1 -1
  23. package/dist/controllers/UnknownOperatingContextController.mjs +1 -1
  24. package/dist/crypto/BrowserCrypto.mjs +1 -1
  25. package/dist/crypto/CryptoOps.mjs +1 -1
  26. package/dist/crypto/PkceGenerator.mjs +1 -1
  27. package/dist/crypto/SignedHttpRequest.mjs +1 -1
  28. package/dist/encode/Base64Decode.mjs +1 -1
  29. package/dist/encode/Base64Encode.mjs +1 -1
  30. package/dist/error/BrowserAuthError.mjs +1 -1
  31. package/dist/error/BrowserAuthErrorCodes.mjs +1 -1
  32. package/dist/error/BrowserConfigurationAuthError.mjs +1 -1
  33. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +1 -1
  34. package/dist/error/NativeAuthError.mjs +1 -1
  35. package/dist/error/NativeAuthErrorCodes.mjs +1 -1
  36. package/dist/error/NestedAppAuthError.mjs +1 -1
  37. package/dist/event/EventHandler.mjs +1 -1
  38. package/dist/event/EventMessage.mjs +1 -1
  39. package/dist/event/EventType.mjs +1 -1
  40. package/dist/index.mjs +1 -1
  41. package/dist/interaction_client/BaseInteractionClient.mjs +1 -1
  42. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
  43. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  44. package/dist/interaction_client/NativeInteractionClient.mjs +4 -2
  45. package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
  46. package/dist/interaction_client/PopupClient.mjs +1 -1
  47. package/dist/interaction_client/RedirectClient.mjs +1 -1
  48. package/dist/interaction_client/SilentAuthCodeClient.mjs +1 -1
  49. package/dist/interaction_client/SilentCacheClient.mjs +1 -1
  50. package/dist/interaction_client/SilentIframeClient.mjs +1 -1
  51. package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
  52. package/dist/interaction_client/SilentRefreshClient.mjs +5 -1
  53. package/dist/interaction_client/SilentRefreshClient.mjs.map +1 -1
  54. package/dist/interaction_client/StandardInteractionClient.mjs +1 -1
  55. package/dist/interaction_handler/InteractionHandler.mjs +1 -1
  56. package/dist/interaction_handler/RedirectHandler.mjs +1 -1
  57. package/dist/interaction_handler/SilentHandler.mjs +1 -1
  58. package/dist/naa/AuthResult.d.ts +7 -0
  59. package/dist/naa/AuthResult.d.ts.map +1 -0
  60. package/dist/naa/BridgeError.mjs +1 -1
  61. package/dist/naa/BridgeProxy.d.ts +11 -15
  62. package/dist/naa/BridgeProxy.d.ts.map +1 -1
  63. package/dist/naa/BridgeProxy.mjs +33 -31
  64. package/dist/naa/BridgeProxy.mjs.map +1 -1
  65. package/dist/naa/BridgeRequest.d.ts +3 -2
  66. package/dist/naa/BridgeRequest.d.ts.map +1 -1
  67. package/dist/naa/BridgeRequestEnvelope.d.ts +2 -3
  68. package/dist/naa/BridgeRequestEnvelope.d.ts.map +1 -1
  69. package/dist/naa/BridgeResponseEnvelope.d.ts +5 -2
  70. package/dist/naa/BridgeResponseEnvelope.d.ts.map +1 -1
  71. package/dist/naa/BridgeStatusCode.d.ts +11 -10
  72. package/dist/naa/BridgeStatusCode.d.ts.map +1 -1
  73. package/dist/naa/BridgeStatusCode.mjs +11 -12
  74. package/dist/naa/BridgeStatusCode.mjs.map +1 -1
  75. package/dist/naa/IBridgeProxy.d.ts +3 -5
  76. package/dist/naa/IBridgeProxy.d.ts.map +1 -1
  77. package/dist/naa/{InitializeBridgeResponse.d.ts → InitContext.d.ts} +2 -2
  78. package/dist/naa/InitContext.d.ts.map +1 -0
  79. package/dist/naa/TokenRequest.d.ts +1 -2
  80. package/dist/naa/TokenRequest.d.ts.map +1 -1
  81. package/dist/naa/TokenResponse.d.ts +1 -3
  82. package/dist/naa/TokenResponse.d.ts.map +1 -1
  83. package/dist/naa/mapping/NestedAppAuthAdapter.d.ts +2 -2
  84. package/dist/naa/mapping/NestedAppAuthAdapter.d.ts.map +1 -1
  85. package/dist/naa/mapping/NestedAppAuthAdapter.mjs +18 -18
  86. package/dist/naa/mapping/NestedAppAuthAdapter.mjs.map +1 -1
  87. package/dist/navigation/NavigationClient.mjs +1 -1
  88. package/dist/network/FetchClient.mjs +1 -1
  89. package/dist/operatingcontext/BaseOperatingContext.d.ts +2 -1
  90. package/dist/operatingcontext/BaseOperatingContext.d.ts.map +1 -1
  91. package/dist/operatingcontext/BaseOperatingContext.mjs +54 -3
  92. package/dist/operatingcontext/BaseOperatingContext.mjs.map +1 -1
  93. package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
  94. package/dist/operatingcontext/TeamsAppOperatingContext.mjs +1 -1
  95. package/dist/operatingcontext/UnknownOperatingContext.mjs +1 -1
  96. package/dist/packageMetadata.d.ts +1 -1
  97. package/dist/packageMetadata.mjs +2 -2
  98. package/dist/response/ResponseHandler.mjs +1 -1
  99. package/dist/telemetry/BrowserPerformanceClient.d.ts +1 -3
  100. package/dist/telemetry/BrowserPerformanceClient.d.ts.map +1 -1
  101. package/dist/telemetry/BrowserPerformanceClient.mjs +63 -26
  102. package/dist/telemetry/BrowserPerformanceClient.mjs.map +1 -1
  103. package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
  104. package/dist/utils/BrowserConstants.d.ts +4 -0
  105. package/dist/utils/BrowserConstants.d.ts.map +1 -1
  106. package/dist/utils/BrowserConstants.mjs +10 -2
  107. package/dist/utils/BrowserConstants.mjs.map +1 -1
  108. package/dist/utils/BrowserProtocolUtils.mjs +1 -1
  109. package/dist/utils/BrowserUtils.mjs +1 -1
  110. package/lib/msal-browser.cjs +3384 -3298
  111. package/lib/msal-browser.cjs.map +1 -1
  112. package/lib/msal-browser.js +3384 -3298
  113. package/lib/msal-browser.js.map +1 -1
  114. package/lib/msal-browser.min.js +66 -71
  115. package/package.json +2 -2
  116. package/src/cache/BrowserCacheManager.ts +7 -19
  117. package/src/cache/TokenCache.ts +3 -2
  118. package/src/controllers/StandardController.ts +50 -21
  119. package/src/interaction_client/NativeInteractionClient.ts +2 -1
  120. package/src/interaction_client/SilentRefreshClient.ts +8 -0
  121. package/src/naa/AuthResult.ts +12 -0
  122. package/src/naa/BridgeProxy.ts +59 -68
  123. package/src/naa/BridgeRequest.ts +6 -2
  124. package/src/naa/BridgeRequestEnvelope.ts +1 -13
  125. package/src/naa/BridgeResponseEnvelope.ts +5 -7
  126. package/src/naa/BridgeStatusCode.ts +12 -10
  127. package/src/naa/IBridgeProxy.ts +3 -14
  128. package/src/naa/{InitializeBridgeResponse.ts → InitContext.ts} +1 -1
  129. package/src/naa/TokenRequest.ts +1 -2
  130. package/src/naa/TokenResponse.ts +1 -4
  131. package/src/naa/mapping/NestedAppAuthAdapter.ts +19 -19
  132. package/src/operatingcontext/BaseOperatingContext.ts +64 -7
  133. package/src/packageMetadata.ts +1 -1
  134. package/src/telemetry/BrowserPerformanceClient.ts +95 -42
  135. package/src/utils/BrowserConstants.ts +11 -0
  136. package/dist/naa/AccountRequests.d.ts +0 -10
  137. package/dist/naa/AccountRequests.d.ts.map +0 -1
  138. package/dist/naa/InitializeBridgeResponse.d.ts.map +0 -1
  139. package/src/naa/AccountRequests.ts +0 -16
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/AzureAD/microsoft-authentication-library-for-js.git"
12
12
  },
13
- "version": "3.6.0",
13
+ "version": "3.7.0",
14
14
  "description": "Microsoft Authentication Library for js",
15
15
  "keywords": [
16
16
  "implicit",
@@ -101,6 +101,6 @@
101
101
  "typescript": "^4.9.5"
102
102
  },
103
103
  "dependencies": {
104
- "@azure/msal-common": "14.5.0"
104
+ "@azure/msal-common": "14.6.0"
105
105
  }
106
106
  }
@@ -866,10 +866,7 @@ export class BrowserCacheManager extends CacheManager {
866
866
  const parsedMetadata = this.validateAndParseJson(value);
867
867
  if (
868
868
  !parsedMetadata ||
869
- !AppMetadataEntity.isAppMetadataEntity(
870
- appMetadataKey,
871
- parsedMetadata
872
- )
869
+ !CacheHelpers.isAppMetadataEntity(appMetadataKey, parsedMetadata)
873
870
  ) {
874
871
  this.logger.trace(
875
872
  "BrowserCacheManager.getAppMetadata: called, no cache hit"
@@ -878,7 +875,7 @@ export class BrowserCacheManager extends CacheManager {
878
875
  }
879
876
 
880
877
  this.logger.trace("BrowserCacheManager.getAppMetadata: cache hit");
881
- return CacheManager.toObject(new AppMetadataEntity(), parsedMetadata);
878
+ return parsedMetadata as AppMetadataEntity;
882
879
  }
883
880
 
884
881
  /**
@@ -887,7 +884,7 @@ export class BrowserCacheManager extends CacheManager {
887
884
  */
888
885
  setAppMetadata(appMetadata: AppMetadataEntity): void {
889
886
  this.logger.trace("BrowserCacheManager.setAppMetadata called");
890
- const appMetadataKey = appMetadata.generateAppMetadataKey();
887
+ const appMetadataKey = CacheHelpers.generateAppMetadataKey(appMetadata);
891
888
  this.setItem(appMetadataKey, JSON.stringify(appMetadata));
892
889
  }
893
890
 
@@ -950,18 +947,12 @@ export class BrowserCacheManager extends CacheManager {
950
947
  const parsedMetadata = this.validateAndParseJson(value);
951
948
  if (
952
949
  parsedMetadata &&
953
- AuthorityMetadataEntity.isAuthorityMetadataEntity(
954
- key,
955
- parsedMetadata
956
- )
950
+ CacheHelpers.isAuthorityMetadataEntity(key, parsedMetadata)
957
951
  ) {
958
952
  this.logger.trace(
959
953
  "BrowserCacheManager.getAuthorityMetadata: cache hit"
960
954
  );
961
- return CacheManager.toObject(
962
- new AuthorityMetadataEntity(),
963
- parsedMetadata
964
- );
955
+ return parsedMetadata as AuthorityMetadataEntity;
965
956
  }
966
957
  return null;
967
958
  }
@@ -1119,7 +1110,7 @@ export class BrowserCacheManager extends CacheManager {
1119
1110
  const parsedThrottlingCache = this.validateAndParseJson(value);
1120
1111
  if (
1121
1112
  !parsedThrottlingCache ||
1122
- !ThrottlingEntity.isThrottlingEntity(
1113
+ !CacheHelpers.isThrottlingEntity(
1123
1114
  throttlingCacheKey,
1124
1115
  parsedThrottlingCache
1125
1116
  )
@@ -1131,10 +1122,7 @@ export class BrowserCacheManager extends CacheManager {
1131
1122
  }
1132
1123
 
1133
1124
  this.logger.trace("BrowserCacheManager.getThrottlingCache: cache hit");
1134
- return CacheManager.toObject(
1135
- new ThrottlingEntity(),
1136
- parsedThrottlingCache
1137
- );
1125
+ return parsedThrottlingCache as ThrottlingEntity;
1138
1126
  }
1139
1127
 
1140
1128
  /**
@@ -270,9 +270,10 @@ export class TokenCache implements ITokenCache {
270
270
  idTokenClaims,
271
271
  base64Decode,
272
272
  clientInfo,
273
+ authority.hostnameAndPort,
273
274
  claimsTenantId,
274
- undefined,
275
- undefined,
275
+ undefined, // authCodePayload
276
+ undefined, // nativeAccountId
276
277
  this.logger
277
278
  );
278
279
 
@@ -43,6 +43,7 @@ import {
43
43
  CacheLookupPolicy,
44
44
  DEFAULT_REQUEST,
45
45
  BrowserConstants,
46
+ iFrameRenewalPolicies,
46
47
  } from "../utils/BrowserConstants";
47
48
  import * as BrowserUtils from "../utils/BrowserUtils";
48
49
  import { RedirectRequest } from "../request/RedirectRequest";
@@ -2078,29 +2079,17 @@ export class StandardController implements IController {
2078
2079
  silentRequest.correlationId
2079
2080
  )(silentRequest, cacheLookupPolicy).catch(
2080
2081
  (refreshTokenError: AuthError) => {
2081
- const isSilentlyResolvable =
2082
- (!(
2083
- refreshTokenError instanceof
2084
- InteractionRequiredAuthError
2085
- ) &&
2086
- (refreshTokenError.errorCode ===
2087
- BrowserConstants.INVALID_GRANT_ERROR ||
2088
- refreshTokenError.errorCode ===
2089
- ClientAuthErrorCodes.tokenRefreshRequired)) ||
2090
- refreshTokenError.errorCode ===
2091
- InteractionRequiredAuthErrorCodes.noTokensFound;
2092
-
2093
- const tryIframeRenewal =
2094
- cacheLookupPolicy ===
2095
- CacheLookupPolicy.Default ||
2096
- cacheLookupPolicy === CacheLookupPolicy.Skip ||
2097
- cacheLookupPolicy ===
2098
- CacheLookupPolicy.RefreshTokenAndNetwork;
2099
-
2100
- if (isSilentlyResolvable && tryIframeRenewal) {
2082
+ const shouldTryToResolveSilently =
2083
+ checkIfRefreshTokenErrorCanBeResolvedSilently(
2084
+ refreshTokenError,
2085
+ silentRequest,
2086
+ cacheLookupPolicy
2087
+ );
2088
+
2089
+ if (shouldTryToResolveSilently) {
2101
2090
  this.logger.verbose(
2102
2091
  "Refresh token expired/invalid or CacheLookupPolicy is set to Skip, attempting acquire token by iframe.",
2103
- request.correlationId
2092
+ silentRequest.correlationId
2104
2093
  );
2105
2094
  return invokeAsync(
2106
2095
  this.acquireTokenBySilentIframe.bind(this),
@@ -2110,6 +2099,7 @@ export class StandardController implements IController {
2110
2099
  silentRequest.correlationId
2111
2100
  )(silentRequest);
2112
2101
  } else {
2102
+ // Error cannot be silently resolved or iframe renewal is not allowed, interaction required
2113
2103
  throw refreshTokenError;
2114
2104
  }
2115
2105
  }
@@ -2155,3 +2145,42 @@ export class StandardController implements IController {
2155
2145
  });
2156
2146
  }
2157
2147
  }
2148
+
2149
+ /**
2150
+ * Determines whether an error thrown by the refresh token endpoint can be resolved without interaction
2151
+ * @param refreshTokenError
2152
+ * @param silentRequest
2153
+ * @param cacheLookupPolicy
2154
+ * @returns
2155
+ */
2156
+ function checkIfRefreshTokenErrorCanBeResolvedSilently(
2157
+ refreshTokenError: AuthError,
2158
+ silentRequest: CommonSilentFlowRequest,
2159
+ cacheLookupPolicy: CacheLookupPolicy
2160
+ ): boolean {
2161
+ const noInteractionRequired = !(
2162
+ refreshTokenError instanceof InteractionRequiredAuthError &&
2163
+ // For refresh token errors, bad_token does not always require interaction (silently resolvable)
2164
+ refreshTokenError.subError !==
2165
+ InteractionRequiredAuthErrorCodes.badToken
2166
+ );
2167
+
2168
+ // Errors that result when the refresh token needs to be replaced
2169
+ const refreshTokenRefreshRequired =
2170
+ refreshTokenError.errorCode === BrowserConstants.INVALID_GRANT_ERROR ||
2171
+ refreshTokenError.errorCode ===
2172
+ ClientAuthErrorCodes.tokenRefreshRequired;
2173
+
2174
+ // Errors that may be resolved before falling back to interaction (through iframe renewal)
2175
+ const isSilentlyResolvable =
2176
+ (noInteractionRequired && refreshTokenRefreshRequired) ||
2177
+ refreshTokenError.errorCode ===
2178
+ InteractionRequiredAuthErrorCodes.noTokensFound ||
2179
+ refreshTokenError.errorCode ===
2180
+ InteractionRequiredAuthErrorCodes.refreshTokenExpired;
2181
+
2182
+ // Only these policies allow for an iframe renewal attempt
2183
+ const tryIframeRenewal = iFrameRenewalPolicies.includes(cacheLookupPolicy);
2184
+
2185
+ return isSilentlyResolvable && tryIframeRenewal;
2186
+ }
@@ -430,8 +430,9 @@ export class NativeInteractionClient extends BaseInteractionClient {
430
430
  idTokenClaims,
431
431
  base64Decode,
432
432
  response.client_info,
433
+ undefined, // environment
433
434
  idTokenClaims.tid,
434
- undefined,
435
+ undefined, // auth code payload
435
436
  response.account.id,
436
437
  this.logger
437
438
  );
@@ -44,6 +44,14 @@ export class SilentRefreshClient extends StandardInteractionClient {
44
44
  ...request,
45
45
  ...baseRequest,
46
46
  };
47
+
48
+ if (request.redirectUri) {
49
+ // Make sure any passed redirectUri is converted to an absolute URL - redirectUri is not a required parameter for refresh token redemption so only include if explicitly provided
50
+ silentRequest.redirectUri = this.getRedirectUri(
51
+ request.redirectUri
52
+ );
53
+ }
54
+
47
55
  const serverTelemetryManager = this.initializeServerTelemetryManager(
48
56
  ApiId.acquireTokenSilent_silentFlow
49
57
  );
@@ -0,0 +1,12 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { AccountInfo } from "./AccountInfo";
7
+ import { TokenResponse } from "./TokenResponse";
8
+
9
+ export type AuthResult = {
10
+ token: TokenResponse;
11
+ account: AccountInfo;
12
+ };
@@ -4,20 +4,17 @@
4
4
  */
5
5
 
6
6
  import { AccountInfo } from "./AccountInfo";
7
- import {
8
- AccountByHomeIdRequest,
9
- AccountByLocalIdRequest,
10
- AccountByUsernameRequest,
11
- } from "./AccountRequests";
12
7
  import { AuthBridge, AuthBridgeResponse } from "./AuthBridge";
8
+ import { AuthResult } from "./AuthResult";
13
9
  import { BridgeCapabilities } from "./BridgeCapabilities";
10
+ import { BridgeError } from "./BridgeError";
14
11
  import { BridgeRequest } from "./BridgeRequest";
15
12
  import { BridgeRequestEnvelope, BridgeMethods } from "./BridgeRequestEnvelope";
16
13
  import { BridgeResponseEnvelope } from "./BridgeResponseEnvelope";
14
+ import { BridgeStatusCode } from "./BridgeStatusCode";
17
15
  import { IBridgeProxy } from "./IBridgeProxy";
18
- import { InitializeBridgeResponse } from "./InitializeBridgeResponse";
16
+ import { InitContext } from "./InitContext";
19
17
  import { TokenRequest } from "./TokenRequest";
20
- import { TokenResponse } from "./TokenResponse";
21
18
 
22
19
  declare global {
23
20
  interface Window {
@@ -31,8 +28,7 @@ declare global {
31
28
  * platform broker
32
29
  */
33
30
  export class BridgeProxy implements IBridgeProxy {
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
- static bridgeRequests: any[] = [];
31
+ static bridgeRequests: BridgeRequest[] = [];
36
32
  static crypto: Crypto;
37
33
  sdkName: string;
38
34
  sdkVersion: string;
@@ -44,7 +40,7 @@ export class BridgeProxy implements IBridgeProxy {
44
40
  * @remarks This method will be called by the create factory method
45
41
  * @remarks If the bridge is not available, this method will throw an error
46
42
  */
47
- protected static async initializeNestedAppAuthBridge(): Promise<InitializeBridgeResponse> {
43
+ protected static async initializeNestedAppAuthBridge(): Promise<InitContext> {
48
44
  if (window === undefined) {
49
45
  throw new Error("window is undefined");
50
46
  }
@@ -75,22 +71,22 @@ export class BridgeProxy implements IBridgeProxy {
75
71
  1
76
72
  );
77
73
  if (responseEnvelope.success) {
78
- request.resolve(responseEnvelope.body);
74
+ request.resolve(responseEnvelope);
79
75
  } else {
80
- request.reject(responseEnvelope.body);
76
+ request.reject(responseEnvelope.error);
81
77
  }
82
78
  }
83
79
  }
84
80
  );
85
81
 
86
- const promise = new Promise<InitializeBridgeResponse>(
82
+ const bridgeResponse = await new Promise<BridgeResponseEnvelope>(
87
83
  (resolve, reject) => {
88
84
  const message: BridgeRequestEnvelope = {
89
85
  messageType: "NestedAppAuthRequest",
90
86
  method: "GetInitContext",
91
87
  requestId: BridgeProxy.getRandomId(),
92
88
  };
93
- const request: BridgeRequest<InitializeBridgeResponse> = {
89
+ const request: BridgeRequest = {
94
90
  requestId: message.requestId,
95
91
  method: message.method,
96
92
  resolve: resolve,
@@ -103,7 +99,9 @@ export class BridgeProxy implements IBridgeProxy {
103
99
  }
104
100
  );
105
101
 
106
- return await promise;
102
+ return BridgeProxy.validateBridgeResultOrThrow(
103
+ bridgeResponse.initContext
104
+ );
107
105
  } catch (error) {
108
106
  window.console.log(error);
109
107
  throw error;
@@ -117,51 +115,37 @@ export class BridgeProxy implements IBridgeProxy {
117
115
  /**
118
116
  * getTokenInteractive - Attempts to get a token interactively from the bridge
119
117
  * @param request A token request
120
- * @returns a promise that resolves to a token response or rejects with a BridgeError
118
+ * @returns a promise that resolves to an auth result or rejects with a BridgeError
121
119
  */
122
- public getTokenInteractive(request: TokenRequest): Promise<TokenResponse> {
123
- return this.sendRequest<TokenResponse>("GetTokenPopup", request);
120
+ public getTokenInteractive(request: TokenRequest): Promise<AuthResult> {
121
+ return this.getToken("GetTokenPopup", request);
124
122
  }
125
123
 
126
124
  /**
127
125
  * getTokenSilent Attempts to get a token silently from the bridge
128
126
  * @param request A token request
129
- * @returns a promise that resolves to a token response or rejects with a BridgeError
127
+ * @returns a promise that resolves to an auth result or rejects with a BridgeError
130
128
  */
131
- public getTokenSilent(request: TokenRequest): Promise<TokenResponse> {
132
- return this.sendRequest<TokenResponse>("GetToken", request);
129
+ public getTokenSilent(request: TokenRequest): Promise<AuthResult> {
130
+ return this.getToken("GetToken", request);
133
131
  }
134
132
 
135
- /**
136
- * getAccountInfo - Gets account information from the bridge
137
- *
138
- * @param request A request for account information
139
- */
140
- public getAccountInfo(
141
- request:
142
- | AccountByHomeIdRequest
143
- | AccountByLocalIdRequest
144
- | AccountByUsernameRequest
145
- ): Promise<AccountInfo> {
146
- let method: BridgeMethods = "GetAccountByHomeId";
147
-
148
- if ((request as AccountByHomeIdRequest).homeAccountId !== undefined) {
149
- method = "GetAccountByHomeId";
150
- }
151
-
152
- if ((request as AccountByLocalIdRequest).localAccountId !== undefined) {
153
- method = "GetAccountByLocalId";
154
- }
155
-
156
- if ((request as AccountByUsernameRequest).username !== undefined) {
157
- method = "GetAccountByUsername";
158
- }
159
-
160
- return this.sendRequest<AccountInfo>(method, request);
133
+ private async getToken(
134
+ requestType: BridgeMethods,
135
+ request: TokenRequest
136
+ ): Promise<AuthResult> {
137
+ const result = await this.sendRequest(requestType, {
138
+ tokenParams: request,
139
+ });
140
+ return {
141
+ token: BridgeProxy.validateBridgeResultOrThrow(result.token),
142
+ account: BridgeProxy.validateBridgeResultOrThrow(result.account),
143
+ };
161
144
  }
162
145
 
163
- public getActiveAccount(): Promise<AccountInfo> {
164
- return this.sendRequest<AccountInfo>("GetActiveAccount", undefined);
146
+ public async getActiveAccount(): Promise<AccountInfo> {
147
+ const result = await this.sendRequest("GetActiveAccount");
148
+ return BridgeProxy.validateBridgeResultOrThrow(result.account);
165
149
  }
166
150
 
167
151
  public getHostCapabilities(): BridgeCapabilities | null {
@@ -173,36 +157,43 @@ export class BridgeProxy implements IBridgeProxy {
173
157
  * @param request A token request
174
158
  * @returns a promise that resolves to a response of provided type or rejects with a BridgeError
175
159
  */
176
- private sendRequest<TResponse>(
160
+ private sendRequest(
177
161
  method: BridgeMethods,
178
- request:
179
- | TokenRequest
180
- | AccountByHomeIdRequest
181
- | AccountByLocalIdRequest
182
- | AccountByUsernameRequest
183
- | undefined
184
- ): Promise<TResponse> {
162
+ requestParams?: Partial<BridgeRequestEnvelope>
163
+ ): Promise<BridgeResponseEnvelope> {
185
164
  const message: BridgeRequestEnvelope = {
186
165
  messageType: "NestedAppAuthRequest",
187
166
  method: method,
188
167
  requestId: BridgeProxy.getRandomId(),
189
- body: request,
168
+ ...requestParams,
190
169
  };
191
170
 
192
- const promise = new Promise<TResponse>((resolve, reject) => {
193
- const request: BridgeRequest<TResponse> = {
194
- requestId: message.requestId,
195
- method: message.method,
196
- resolve: resolve,
197
- reject: reject,
198
- };
199
- BridgeProxy.bridgeRequests.push(request);
200
- window.nestedAppAuthBridge.postMessage(JSON.stringify(message));
201
- });
171
+ const promise = new Promise<BridgeResponseEnvelope>(
172
+ (resolve, reject) => {
173
+ const request: BridgeRequest = {
174
+ requestId: message.requestId,
175
+ method: message.method,
176
+ resolve: resolve,
177
+ reject: reject,
178
+ };
179
+ BridgeProxy.bridgeRequests.push(request);
180
+ window.nestedAppAuthBridge.postMessage(JSON.stringify(message));
181
+ }
182
+ );
202
183
 
203
184
  return promise;
204
185
  }
205
186
 
187
+ private static validateBridgeResultOrThrow<T>(input: T | undefined): T {
188
+ if (input === undefined) {
189
+ const bridgeError: BridgeError = {
190
+ status: BridgeStatusCode.NestedAppAuthUnavailable,
191
+ };
192
+ throw bridgeError;
193
+ }
194
+ return input;
195
+ }
196
+
206
197
  /**
207
198
  * Private constructor for BridgeProxy
208
199
  * @param sdkName The name of the SDK being used to make requests on behalf of the app
@@ -3,10 +3,14 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- export type BridgeRequest<TResponse> = {
6
+ import { BridgeResponseEnvelope } from "./BridgeResponseEnvelope";
7
+
8
+ export type BridgeRequest = {
7
9
  requestId: string;
8
10
  method: string;
9
- resolve: (value: TResponse | PromiseLike<TResponse>) => void;
11
+ resolve: (
12
+ value: BridgeResponseEnvelope | PromiseLike<BridgeResponseEnvelope>
13
+ ) => void;
10
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
15
  reject: (reason?: any) => void;
12
16
  };
@@ -4,19 +4,11 @@
4
4
  */
5
5
 
6
6
  import { TokenRequest } from "./TokenRequest";
7
- import {
8
- AccountByHomeIdRequest,
9
- AccountByLocalIdRequest,
10
- AccountByUsernameRequest,
11
- } from "./AccountRequests";
12
7
 
13
8
  export type BridgeMethods =
14
9
  | "GetToken"
15
10
  | "GetActiveAccount"
16
11
  | "GetAllAccounts"
17
- | "GetAccountByHomeId"
18
- | "GetAccountByLocalId"
19
- | "GetAccountByUsername"
20
12
  | "GetInitContext"
21
13
  | "GetTokenPopup";
22
14
 
@@ -27,11 +19,7 @@ export type BridgeRequestEnvelope = {
27
19
  clientLibrary?: string;
28
20
  clientLibraryVersion?: string;
29
21
  requestId: string;
30
- body?:
31
- | TokenRequest
32
- | AccountByHomeIdRequest
33
- | AccountByLocalIdRequest
34
- | AccountByUsernameRequest;
22
+ tokenParams?: TokenRequest;
35
23
  };
36
24
 
37
25
  export function isBridgeRequestEnvelope(
@@ -6,16 +6,14 @@
6
6
  import { BridgeError } from "./BridgeError";
7
7
  import { TokenResponse } from "./TokenResponse";
8
8
  import { AccountInfo } from "./AccountInfo";
9
- import { InitializeBridgeResponse } from "./InitializeBridgeResponse";
9
+ import { InitContext } from "./InitContext";
10
10
 
11
11
  export type BridgeResponseEnvelope = {
12
12
  messageType: "NestedAppAuthResponse";
13
13
  requestId: string;
14
14
  success: boolean; // false if body is error
15
- body:
16
- | TokenResponse
17
- | BridgeError
18
- | AccountInfo
19
- | AccountInfo[]
20
- | InitializeBridgeResponse;
15
+ token?: TokenResponse;
16
+ error?: BridgeError;
17
+ account?: AccountInfo;
18
+ initContext?: InitContext;
21
19
  };
@@ -3,13 +3,15 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- export enum BridgeStatusCode {
7
- USER_INTERACTION_REQUIRED = "USER_INTERACTION_REQUIRED",
8
- USER_CANCEL = "USER_CANCEL",
9
- NO_NETWORK = "NO_NETWORK",
10
- TRANSIENT_ERROR = "TRANSIENT_ERROR",
11
- PERSISTENT_ERROR = "PERSISTENT_ERROR",
12
- DISABLED = "DISABLED",
13
- ACCOUNT_UNAVAILABLE = "ACCOUNT_UNAVAILABLE",
14
- NESTED_APP_AUTH_UNAVAILABLE = "NESTED_APP_AUTH_UNAVAILABLE", // NAA is unavailable in the current context, can retry with standard browser based auth
15
- }
6
+ export const BridgeStatusCode = {
7
+ UserInteractionRequired: "USER_INTERACTION_REQUIRED",
8
+ UserCancel: "USER_CANCEL",
9
+ NoNetwork: "NO_NETWORK",
10
+ TransientError: "TRANSIENT_ERROR",
11
+ PersistentError: "PERSISTENT_ERROR",
12
+ Disabled: "DISABLED",
13
+ AccountUnavailable: "ACCOUNT_UNAVAILABLE",
14
+ NestedAppAuthUnavailable: "NESTED_APP_AUTH_UNAVAILABLE", // NAA is unavailable in the current context, can retry with standard browser based auth
15
+ } as const;
16
+ export type BridgeStatusCode =
17
+ (typeof BridgeStatusCode)[keyof typeof BridgeStatusCode];
@@ -4,24 +4,13 @@
4
4
  */
5
5
 
6
6
  import { AccountInfo } from "./AccountInfo";
7
- import {
8
- AccountByHomeIdRequest,
9
- AccountByLocalIdRequest,
10
- AccountByUsernameRequest,
11
- } from "./AccountRequests";
7
+ import { AuthResult } from "./AuthResult";
12
8
  import { BridgeCapabilities } from "./BridgeCapabilities";
13
9
  import { TokenRequest } from "./TokenRequest";
14
- import { TokenResponse } from "./TokenResponse";
15
10
 
16
11
  export interface IBridgeProxy {
17
- getTokenInteractive(request: TokenRequest): Promise<TokenResponse>;
18
- getTokenSilent(request: TokenRequest): Promise<TokenResponse>;
19
- getAccountInfo(
20
- request:
21
- | AccountByHomeIdRequest
22
- | AccountByLocalIdRequest
23
- | AccountByUsernameRequest
24
- ): Promise<AccountInfo>;
12
+ getTokenInteractive(request: TokenRequest): Promise<AuthResult>;
13
+ getTokenSilent(request: TokenRequest): Promise<AuthResult>;
25
14
  getActiveAccount(): Promise<AccountInfo>;
26
15
  getHostCapabilities(): BridgeCapabilities | null;
27
16
  }
@@ -5,7 +5,7 @@
5
5
 
6
6
  import { BridgeCapabilities } from "./BridgeCapabilities";
7
7
 
8
- export interface InitializeBridgeResponse {
8
+ export interface InitContext {
9
9
  capabilities?: BridgeCapabilities;
10
10
  sdkName: string;
11
11
  sdkVersion: string;
@@ -4,12 +4,11 @@
4
4
  */
5
5
 
6
6
  export type TokenRequest = {
7
- userObjectId?: string; // Account identifier used by OneAuth
7
+ platformBrokerId?: string; // Account identifier used by OneAuth
8
8
  clientId: string;
9
9
  authority?: string;
10
10
  scope: string;
11
11
  correlationId: string;
12
- nonce?: string;
13
12
  claims?: string;
14
13
  state?: string;
15
14
  reqCnf?: string; // Having OneAuth own the keypair is better for hardware token binding support
@@ -3,15 +3,12 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { AccountInfo } from "./AccountInfo";
7
-
8
6
  export type TokenResponse = {
9
7
  access_token: string;
10
- account: AccountInfo;
11
8
  expires_in: number;
12
9
  id_token: string;
13
10
  properties: TokenResponseProperties | null;
14
- scope: string;
11
+ scope?: string;
15
12
  shr?: string; // token binding enabled at native layer it is the access token, not the signing keys
16
13
  extendedLifetimeToken?: boolean;
17
14
  authority?: string;