@azure/msal-common 15.2.1 → 15.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 (149) hide show
  1. package/dist/account/AccountInfo.mjs +1 -1
  2. package/dist/account/AuthToken.mjs +1 -1
  3. package/dist/account/CcsCredential.mjs +1 -1
  4. package/dist/account/ClientInfo.mjs +1 -1
  5. package/dist/account/TokenClaims.mjs +1 -1
  6. package/dist/authority/Authority.mjs +1 -1
  7. package/dist/authority/AuthorityFactory.mjs +1 -1
  8. package/dist/authority/AuthorityMetadata.mjs +1 -1
  9. package/dist/authority/AuthorityOptions.mjs +1 -1
  10. package/dist/authority/AuthorityType.mjs +1 -1
  11. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
  12. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
  13. package/dist/authority/OpenIdConfigResponse.mjs +1 -1
  14. package/dist/authority/ProtocolMode.mjs +1 -1
  15. package/dist/authority/RegionDiscovery.mjs +1 -1
  16. package/dist/cache/CacheManager.mjs +1 -1
  17. package/dist/cache/entities/AccountEntity.mjs +1 -1
  18. package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
  19. package/dist/cache/utils/CacheHelpers.mjs +1 -1
  20. package/dist/client/AuthorizationCodeClient.d.ts +0 -31
  21. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  22. package/dist/client/AuthorizationCodeClient.mjs +41 -246
  23. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  24. package/dist/client/BaseClient.d.ts.map +1 -1
  25. package/dist/client/BaseClient.mjs +9 -10
  26. package/dist/client/BaseClient.mjs.map +1 -1
  27. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  28. package/dist/client/RefreshTokenClient.mjs +27 -29
  29. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  30. package/dist/client/SilentFlowClient.mjs +1 -1
  31. package/dist/config/ClientConfiguration.mjs +1 -1
  32. package/dist/constants/AADServerParamKeys.d.ts +1 -0
  33. package/dist/constants/AADServerParamKeys.d.ts.map +1 -1
  34. package/dist/constants/AADServerParamKeys.mjs +4 -3
  35. package/dist/constants/AADServerParamKeys.mjs.map +1 -1
  36. package/dist/crypto/ICrypto.mjs +1 -1
  37. package/dist/crypto/JoseHeader.mjs +1 -1
  38. package/dist/crypto/PopTokenGenerator.mjs +1 -1
  39. package/dist/error/AuthError.mjs +1 -1
  40. package/dist/error/AuthErrorCodes.mjs +1 -1
  41. package/dist/error/CacheError.mjs +1 -1
  42. package/dist/error/CacheErrorCodes.mjs +1 -1
  43. package/dist/error/ClientAuthError.mjs +1 -1
  44. package/dist/error/ClientAuthErrorCodes.mjs +1 -1
  45. package/dist/error/ClientConfigurationError.mjs +1 -1
  46. package/dist/error/ClientConfigurationErrorCodes.mjs +1 -1
  47. package/dist/error/InteractionRequiredAuthError.mjs +1 -1
  48. package/dist/error/InteractionRequiredAuthErrorCodes.mjs +1 -1
  49. package/dist/error/JoseHeaderError.mjs +1 -1
  50. package/dist/error/JoseHeaderErrorCodes.mjs +1 -1
  51. package/dist/error/NetworkError.mjs +1 -1
  52. package/dist/error/ServerError.mjs +1 -1
  53. package/dist/exports-common.d.ts +3 -2
  54. package/dist/exports-common.d.ts.map +1 -1
  55. package/dist/index-browser.mjs +5 -2
  56. package/dist/index-browser.mjs.map +1 -1
  57. package/dist/index-node.mjs +5 -2
  58. package/dist/index-node.mjs.map +1 -1
  59. package/dist/index.mjs +5 -2
  60. package/dist/index.mjs.map +1 -1
  61. package/dist/logger/Logger.mjs +1 -1
  62. package/dist/network/INetworkModule.mjs +1 -1
  63. package/dist/network/RequestThumbprint.mjs +1 -1
  64. package/dist/network/ThrottlingUtils.mjs +1 -1
  65. package/dist/packageMetadata.d.ts +1 -1
  66. package/dist/packageMetadata.mjs +2 -2
  67. package/dist/protocol/Authorize.d.ts +37 -0
  68. package/dist/protocol/Authorize.d.ts.map +1 -0
  69. package/dist/protocol/Authorize.mjs +237 -0
  70. package/dist/protocol/Authorize.mjs.map +1 -0
  71. package/dist/request/AuthenticationHeaderParser.mjs +1 -1
  72. package/dist/request/RequestParameterBuilder.d.ts +206 -218
  73. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  74. package/dist/request/RequestParameterBuilder.mjs +356 -369
  75. package/dist/request/RequestParameterBuilder.mjs.map +1 -1
  76. package/dist/request/RequestValidator.mjs +1 -1
  77. package/dist/request/ScopeSet.mjs +1 -1
  78. package/dist/response/AuthorizeResponse.d.ts +72 -0
  79. package/dist/response/AuthorizeResponse.d.ts.map +1 -0
  80. package/dist/response/ResponseHandler.d.ts +0 -8
  81. package/dist/response/ResponseHandler.d.ts.map +1 -1
  82. package/dist/response/ResponseHandler.mjs +2 -49
  83. package/dist/response/ResponseHandler.mjs.map +1 -1
  84. package/dist/telemetry/performance/PerformanceClient.mjs +1 -1
  85. package/dist/telemetry/performance/PerformanceEvent.d.ts +1 -2
  86. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  87. package/dist/telemetry/performance/PerformanceEvent.mjs +2 -11
  88. package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
  89. package/dist/telemetry/performance/StubPerformanceClient.mjs +1 -1
  90. package/dist/telemetry/server/ServerTelemetryManager.mjs +1 -1
  91. package/dist/url/UrlString.mjs +1 -1
  92. package/dist/utils/ClientAssertionUtils.mjs +1 -1
  93. package/dist/utils/Constants.mjs +1 -1
  94. package/dist/utils/FunctionWrappers.mjs +1 -1
  95. package/dist/utils/ProtocolUtils.mjs +1 -1
  96. package/dist/utils/StringUtils.mjs +1 -1
  97. package/dist/utils/TimeUtils.mjs +1 -1
  98. package/dist/utils/UrlUtils.d.ts +6 -2
  99. package/dist/utils/UrlUtils.d.ts.map +1 -1
  100. package/dist/utils/UrlUtils.mjs +12 -2
  101. package/dist/utils/UrlUtils.mjs.map +1 -1
  102. package/lib/index-browser.cjs +3 -2
  103. package/lib/index-browser.cjs.map +1 -1
  104. package/lib/{index-node--LMD5Re1.js → index-node-BjtDFnOl.js} +782 -768
  105. package/lib/index-node-BjtDFnOl.js.map +1 -0
  106. package/lib/index-node.cjs +3 -2
  107. package/lib/index-node.cjs.map +1 -1
  108. package/lib/index.cjs +3 -2
  109. package/lib/index.cjs.map +1 -1
  110. package/lib/types/client/AuthorizationCodeClient.d.ts +0 -31
  111. package/lib/types/client/AuthorizationCodeClient.d.ts.map +1 -1
  112. package/lib/types/client/BaseClient.d.ts.map +1 -1
  113. package/lib/types/client/RefreshTokenClient.d.ts.map +1 -1
  114. package/lib/types/constants/AADServerParamKeys.d.ts +1 -0
  115. package/lib/types/constants/AADServerParamKeys.d.ts.map +1 -1
  116. package/lib/types/exports-common.d.ts +3 -2
  117. package/lib/types/exports-common.d.ts.map +1 -1
  118. package/lib/types/packageMetadata.d.ts +1 -1
  119. package/lib/types/protocol/Authorize.d.ts +37 -0
  120. package/lib/types/protocol/Authorize.d.ts.map +1 -0
  121. package/lib/types/request/RequestParameterBuilder.d.ts +206 -218
  122. package/lib/types/request/RequestParameterBuilder.d.ts.map +1 -1
  123. package/lib/types/response/AuthorizeResponse.d.ts +72 -0
  124. package/lib/types/response/AuthorizeResponse.d.ts.map +1 -0
  125. package/lib/types/response/ResponseHandler.d.ts +0 -8
  126. package/lib/types/response/ResponseHandler.d.ts.map +1 -1
  127. package/lib/types/telemetry/performance/PerformanceEvent.d.ts +1 -2
  128. package/lib/types/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  129. package/lib/types/utils/UrlUtils.d.ts +6 -2
  130. package/lib/types/utils/UrlUtils.d.ts.map +1 -1
  131. package/package.json +1 -1
  132. package/src/client/AuthorizationCodeClient.ts +84 -395
  133. package/src/client/BaseClient.ts +20 -12
  134. package/src/client/RefreshTokenClient.ts +60 -30
  135. package/src/constants/AADServerParamKeys.ts +1 -0
  136. package/src/exports-common.ts +4 -2
  137. package/src/packageMetadata.ts +1 -1
  138. package/src/protocol/Authorize.ts +409 -0
  139. package/src/request/RequestParameterBuilder.ts +508 -543
  140. package/src/response/AuthorizeResponse.ts +76 -0
  141. package/src/response/ResponseHandler.ts +0 -98
  142. package/src/telemetry/performance/PerformanceEvent.ts +1 -11
  143. package/src/utils/UrlUtils.ts +18 -4
  144. package/dist/response/ServerAuthorizationCodeResponse.d.ts +0 -27
  145. package/dist/response/ServerAuthorizationCodeResponse.d.ts.map +0 -1
  146. package/lib/index-node--LMD5Re1.js.map +0 -1
  147. package/lib/types/response/ServerAuthorizationCodeResponse.d.ts +0 -27
  148. package/lib/types/response/ServerAuthorizationCodeResponse.d.ts.map +0 -1
  149. package/src/response/ServerAuthorizationCodeResponse.ts +0 -34
@@ -0,0 +1,76 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /**
7
+ * Response properties that may be returned by the /authorize endpoint
8
+ */
9
+ export type AuthorizeResponse = {
10
+ /**
11
+ * Authorization Code to be exchanged for tokens
12
+ */
13
+ code?: string;
14
+ /**
15
+ * Client info object containing UserId and TenantId
16
+ */
17
+ client_info?: string;
18
+ /**
19
+ * State string, should match what was sent on request
20
+ */
21
+ state?: string;
22
+ /**
23
+ * Cloud instance returned when application is instance aware
24
+ */
25
+ cloud_instance_name?: string;
26
+ /**
27
+ * Cloud instance hostname returned when application is instance aware
28
+ */
29
+ cloud_instance_host_name?: string;
30
+ /**
31
+ * AAD Graph hostname returned when application is instance aware
32
+ * https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-graph-api
33
+ */
34
+ cloud_graph_host_name?: string;
35
+ /**
36
+ * Microsoft Graph hostname returned when application is instance aware
37
+ * https://docs.microsoft.com/en-us/graph/overview
38
+ */
39
+ msgraph_host?: string;
40
+ /**
41
+ * Server error code
42
+ */
43
+ error?: string;
44
+ /**
45
+ * Server error URI
46
+ */
47
+ error_uri?: string;
48
+ /**
49
+ * Server error description
50
+ */
51
+ error_description?: string;
52
+ /**
53
+ * Server Sub-Error
54
+ */
55
+ suberror?: string;
56
+ /**
57
+ * Timestamp of request
58
+ */
59
+ timestamp?: string;
60
+ /**
61
+ * Trace Id used to look up request in logs
62
+ */
63
+ trace_id?: string;
64
+ /**
65
+ * Correlation ID use to look up request in logs
66
+ */
67
+ correlation_id?: string;
68
+ /**
69
+ * Claims
70
+ */
71
+ claims?: string;
72
+ /**
73
+ * AccountId for the user, returned when platform broker is available to use
74
+ */
75
+ accountId?: string;
76
+ };
@@ -9,7 +9,6 @@ import {
9
9
  ClientAuthErrorCodes,
10
10
  createClientAuthError,
11
11
  } from "../error/ClientAuthError.js";
12
- import { ServerAuthorizationCodeResponse } from "./ServerAuthorizationCodeResponse.js";
13
12
  import { Logger } from "../logger/Logger.js";
14
13
  import { ServerError } from "../error/ServerError.js";
15
14
  import { ScopeSet } from "../request/ScopeSet.js";
@@ -54,19 +53,6 @@ import {
54
53
  import * as CacheHelpers from "../cache/utils/CacheHelpers.js";
55
54
  import * as TimeUtils from "../utils/TimeUtils.js";
56
55
 
57
- function parseServerErrorNo(
58
- serverResponse: ServerAuthorizationCodeResponse
59
- ): string | undefined {
60
- const errorCodePrefix = "code=";
61
- const errorCodePrefixIndex =
62
- serverResponse.error_uri?.lastIndexOf(errorCodePrefix);
63
- return errorCodePrefixIndex && errorCodePrefixIndex >= 0
64
- ? serverResponse.error_uri?.substring(
65
- errorCodePrefixIndex + errorCodePrefix.length
66
- )
67
- : undefined;
68
- }
69
-
70
56
  /**
71
57
  * Class that handles response parsing.
72
58
  * @internal
@@ -99,90 +85,6 @@ export class ResponseHandler {
99
85
  this.performanceClient = performanceClient;
100
86
  }
101
87
 
102
- /**
103
- * Function which validates server authorization code response.
104
- * @param serverResponseHash
105
- * @param requestState
106
- * @param cryptoObj
107
- */
108
- validateServerAuthorizationCodeResponse(
109
- serverResponse: ServerAuthorizationCodeResponse,
110
- requestState: string
111
- ): void {
112
- if (!serverResponse.state || !requestState) {
113
- throw serverResponse.state
114
- ? createClientAuthError(
115
- ClientAuthErrorCodes.stateNotFound,
116
- "Cached State"
117
- )
118
- : createClientAuthError(
119
- ClientAuthErrorCodes.stateNotFound,
120
- "Server State"
121
- );
122
- }
123
-
124
- let decodedServerResponseState: string;
125
- let decodedRequestState: string;
126
-
127
- try {
128
- decodedServerResponseState = decodeURIComponent(
129
- serverResponse.state
130
- );
131
- } catch (e) {
132
- throw createClientAuthError(
133
- ClientAuthErrorCodes.invalidState,
134
- serverResponse.state
135
- );
136
- }
137
-
138
- try {
139
- decodedRequestState = decodeURIComponent(requestState);
140
- } catch (e) {
141
- throw createClientAuthError(
142
- ClientAuthErrorCodes.invalidState,
143
- serverResponse.state
144
- );
145
- }
146
-
147
- if (decodedServerResponseState !== decodedRequestState) {
148
- throw createClientAuthError(ClientAuthErrorCodes.stateMismatch);
149
- }
150
-
151
- // Check for error
152
- if (
153
- serverResponse.error ||
154
- serverResponse.error_description ||
155
- serverResponse.suberror
156
- ) {
157
- const serverErrorNo = parseServerErrorNo(serverResponse);
158
- if (
159
- isInteractionRequiredError(
160
- serverResponse.error,
161
- serverResponse.error_description,
162
- serverResponse.suberror
163
- )
164
- ) {
165
- throw new InteractionRequiredAuthError(
166
- serverResponse.error || "",
167
- serverResponse.error_description,
168
- serverResponse.suberror,
169
- serverResponse.timestamp || "",
170
- serverResponse.trace_id || "",
171
- serverResponse.correlation_id || "",
172
- serverResponse.claims || "",
173
- serverErrorNo
174
- );
175
- }
176
-
177
- throw new ServerError(
178
- serverResponse.error || "",
179
- serverResponse.error_description,
180
- serverResponse.suberror,
181
- serverErrorNo
182
- );
183
- }
184
- }
185
-
186
88
  /**
187
89
  * Function which validates server authorization token response.
188
90
  * @param serverResponse
@@ -214,13 +214,12 @@ export const PerformanceEvents = {
214
214
  "standardInteractionClientGetClientConfiguration",
215
215
  StandardInteractionClientInitializeAuthorizationRequest:
216
216
  "standardInteractionClientInitializeAuthorizationRequest",
217
- StandardInteractionClientInitializeAuthorizationCodeRequest:
218
- "standardInteractionClientInitializeAuthorizationCodeRequest",
219
217
 
220
218
  /**
221
219
  * getAuthCodeUrl API (msal-browser and msal-node).
222
220
  */
223
221
  GetAuthCodeUrl: "getAuthCodeUrl",
222
+ GetStandardParams: "getStandardParams",
224
223
 
225
224
  /**
226
225
  * Functions from InteractionHandler (msal-browser)
@@ -235,7 +234,6 @@ export const PerformanceEvents = {
235
234
  AuthClientAcquireToken: "authClientAcquireToken",
236
235
  AuthClientExecuteTokenRequest: "authClientExecuteTokenRequest",
237
236
  AuthClientCreateTokenRequestBody: "authClientCreateTokenRequestBody",
238
- AuthClientCreateQueryString: "authClientCreateQueryString",
239
237
 
240
238
  /**
241
239
  * Generate functions in PopTokenGenerator (msal-common)
@@ -433,10 +431,6 @@ export const PerformanceEventAbbreviations: ReadonlyMap<string, string> =
433
431
  PerformanceEvents.StandardInteractionClientInitializeAuthorizationRequest,
434
432
  "StdIntClientInitAuthReq",
435
433
  ],
436
- [
437
- PerformanceEvents.StandardInteractionClientInitializeAuthorizationCodeRequest,
438
- "StdIntClientInitAuthCodeReq",
439
- ],
440
434
 
441
435
  [PerformanceEvents.GetAuthCodeUrl, "GetAuthCodeUrl"],
442
436
 
@@ -453,10 +447,6 @@ export const PerformanceEventAbbreviations: ReadonlyMap<string, string> =
453
447
  PerformanceEvents.AuthClientCreateTokenRequestBody,
454
448
  "AuthClientCreateTReqBody",
455
449
  ],
456
- [
457
- PerformanceEvents.AuthClientCreateQueryString,
458
- "AuthClientCreateQueryStr",
459
- ],
460
450
  [PerformanceEvents.PopTokenGenerateCnf, "PopTGenCnf"],
461
451
  [PerformanceEvents.PopTokenGenerateKid, "PopTGenKid"],
462
452
  [PerformanceEvents.HandleServerTokenResponse, "HandleServerTRes"],
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { ServerAuthorizationCodeResponse } from "../response/ServerAuthorizationCodeResponse.js";
6
+ import { AuthorizeResponse } from "../response/AuthorizeResponse.js";
7
7
  import {
8
8
  ClientAuthErrorCodes,
9
9
  createClientAuthError,
@@ -31,7 +31,7 @@ export function stripLeadingHashOrQuery(responseString: string): string {
31
31
  */
32
32
  export function getDeserializedResponse(
33
33
  responseString: string
34
- ): ServerAuthorizationCodeResponse | null {
34
+ ): AuthorizeResponse | null {
35
35
  // Check if given hash is empty
36
36
  if (!responseString || responseString.indexOf("=") < 0) {
37
37
  return null;
@@ -40,8 +40,9 @@ export function getDeserializedResponse(
40
40
  // Strip the # or ? symbol if present
41
41
  const normalizedResponse = stripLeadingHashOrQuery(responseString);
42
42
  // If # symbol was not present, above will return empty string, so give original hash value
43
- const deserializedHash: ServerAuthorizationCodeResponse =
44
- Object.fromEntries(new URLSearchParams(normalizedResponse));
43
+ const deserializedHash: AuthorizeResponse = Object.fromEntries(
44
+ new URLSearchParams(normalizedResponse)
45
+ );
45
46
 
46
47
  // Check for known response properties
47
48
  if (
@@ -58,3 +59,16 @@ export function getDeserializedResponse(
58
59
 
59
60
  return null;
60
61
  }
62
+
63
+ /**
64
+ * Utility to create a URL from the params map
65
+ */
66
+ export function mapToQueryString(parameters: Map<string, string>): string {
67
+ const queryParameterArray: Array<string> = new Array<string>();
68
+
69
+ parameters.forEach((value, key) => {
70
+ queryParameterArray.push(`${key}=${encodeURIComponent(value)}`);
71
+ });
72
+
73
+ return queryParameterArray.join("&");
74
+ }
@@ -1,27 +0,0 @@
1
- /**
2
- * Deserialized response object from server authorization code request.
3
- * - code: authorization code from server
4
- * - client_info: client info object
5
- * - state: OAuth2 request state
6
- * - error: error sent back in hash
7
- * - error: description
8
- */
9
- export type ServerAuthorizationCodeResponse = {
10
- code?: string;
11
- client_info?: string;
12
- state?: string;
13
- cloud_instance_name?: string;
14
- cloud_instance_host_name?: string;
15
- cloud_graph_host_name?: string;
16
- msgraph_host?: string;
17
- error?: string;
18
- error_uri?: string;
19
- error_description?: string;
20
- suberror?: string;
21
- timestamp?: string;
22
- trace_id?: string;
23
- correlation_id?: string;
24
- claims?: string;
25
- accountId?: string;
26
- };
27
- //# sourceMappingURL=ServerAuthorizationCodeResponse.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ServerAuthorizationCodeResponse.d.ts","sourceRoot":"","sources":["../../src/response/ServerAuthorizationCodeResponse.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAE1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC"}