@azure/msal-node 2.0.2 → 2.1.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 (191) hide show
  1. package/README.md +3 -1
  2. package/dist/cache/NodeStorage.cjs +1 -1
  3. package/dist/cache/NodeStorage.cjs.map +1 -1
  4. package/dist/cache/NodeStorage.d.ts +1 -1
  5. package/dist/cache/NodeStorage.d.ts.map +1 -1
  6. package/dist/cache/NodeStorage.mjs +1 -1
  7. package/dist/cache/NodeStorage.mjs.map +1 -1
  8. package/dist/cache/TokenCache.cjs +5 -9
  9. package/dist/cache/TokenCache.cjs.map +1 -1
  10. package/dist/cache/TokenCache.d.ts +3 -3
  11. package/dist/cache/TokenCache.d.ts.map +1 -1
  12. package/dist/cache/TokenCache.mjs +6 -10
  13. package/dist/cache/TokenCache.mjs.map +1 -1
  14. package/dist/cache/distributed/DistributedCachePlugin.cjs +1 -1
  15. package/dist/cache/distributed/DistributedCachePlugin.cjs.map +1 -1
  16. package/dist/cache/distributed/DistributedCachePlugin.d.ts +2 -2
  17. package/dist/cache/distributed/DistributedCachePlugin.d.ts.map +1 -1
  18. package/dist/cache/distributed/DistributedCachePlugin.mjs +1 -1
  19. package/dist/cache/distributed/DistributedCachePlugin.mjs.map +1 -1
  20. package/dist/cache/serializer/Deserializer.cjs +2 -4
  21. package/dist/cache/serializer/Deserializer.cjs.map +1 -1
  22. package/dist/cache/serializer/Deserializer.d.ts +1 -1
  23. package/dist/cache/serializer/Deserializer.d.ts.map +1 -1
  24. package/dist/cache/serializer/Deserializer.mjs +3 -5
  25. package/dist/cache/serializer/Deserializer.mjs.map +1 -1
  26. package/dist/cache/serializer/Serializer.cjs +1 -1
  27. package/dist/cache/serializer/Serializer.cjs.map +1 -1
  28. package/dist/cache/serializer/Serializer.d.ts +1 -1
  29. package/dist/cache/serializer/Serializer.d.ts.map +1 -1
  30. package/dist/cache/serializer/Serializer.mjs +1 -1
  31. package/dist/cache/serializer/Serializer.mjs.map +1 -1
  32. package/dist/client/ClientApplication.cjs +2 -2
  33. package/dist/client/ClientApplication.cjs.map +1 -1
  34. package/dist/client/ClientApplication.d.ts +10 -10
  35. package/dist/client/ClientApplication.d.ts.map +1 -1
  36. package/dist/client/ClientApplication.mjs +2 -2
  37. package/dist/client/ClientApplication.mjs.map +1 -1
  38. package/dist/client/ClientAssertion.cjs +1 -1
  39. package/dist/client/ClientAssertion.cjs.map +1 -1
  40. package/dist/client/ClientAssertion.d.ts +1 -1
  41. package/dist/client/ClientAssertion.d.ts.map +1 -1
  42. package/dist/client/ClientAssertion.mjs +1 -1
  43. package/dist/client/ClientAssertion.mjs.map +1 -1
  44. package/dist/client/ClientCredentialClient.cjs +26 -4
  45. package/dist/client/ClientCredentialClient.cjs.map +1 -1
  46. package/dist/client/ClientCredentialClient.d.ts +1 -0
  47. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  48. package/dist/client/ClientCredentialClient.mjs +27 -5
  49. package/dist/client/ClientCredentialClient.mjs.map +1 -1
  50. package/dist/client/ConfidentialClientApplication.cjs +4 -5
  51. package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
  52. package/dist/client/ConfidentialClientApplication.d.ts +5 -5
  53. package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
  54. package/dist/client/ConfidentialClientApplication.mjs +5 -6
  55. package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
  56. package/dist/client/DeviceCodeClient.cjs +3 -3
  57. package/dist/client/DeviceCodeClient.cjs.map +1 -1
  58. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  59. package/dist/client/DeviceCodeClient.mjs +4 -4
  60. package/dist/client/DeviceCodeClient.mjs.map +1 -1
  61. package/dist/client/IConfidentialClientApplication.d.ts +8 -8
  62. package/dist/client/IConfidentialClientApplication.d.ts.map +1 -1
  63. package/dist/client/IPublicClientApplication.d.ts +9 -9
  64. package/dist/client/IPublicClientApplication.d.ts.map +1 -1
  65. package/dist/client/OnBehalfOfClient.cjs +7 -8
  66. package/dist/client/OnBehalfOfClient.cjs.map +1 -1
  67. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  68. package/dist/client/OnBehalfOfClient.mjs +7 -8
  69. package/dist/client/OnBehalfOfClient.mjs.map +1 -1
  70. package/dist/client/PublicClientApplication.cjs +36 -29
  71. package/dist/client/PublicClientApplication.cjs.map +1 -1
  72. package/dist/client/PublicClientApplication.d.ts +7 -7
  73. package/dist/client/PublicClientApplication.d.ts.map +1 -1
  74. package/dist/client/PublicClientApplication.mjs +40 -33
  75. package/dist/client/PublicClientApplication.mjs.map +1 -1
  76. package/dist/client/UsernamePasswordClient.cjs +2 -2
  77. package/dist/client/UsernamePasswordClient.cjs.map +1 -1
  78. package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
  79. package/dist/client/UsernamePasswordClient.mjs +2 -2
  80. package/dist/client/UsernamePasswordClient.mjs.map +1 -1
  81. package/dist/config/Configuration.cjs +1 -1
  82. package/dist/config/Configuration.cjs.map +1 -1
  83. package/dist/config/Configuration.mjs +1 -1
  84. package/dist/config/Configuration.mjs.map +1 -1
  85. package/dist/crypto/CryptoProvider.cjs +1 -1
  86. package/dist/crypto/CryptoProvider.cjs.map +1 -1
  87. package/dist/crypto/CryptoProvider.mjs +1 -1
  88. package/dist/crypto/CryptoProvider.mjs.map +1 -1
  89. package/dist/crypto/GuidGenerator.cjs +1 -1
  90. package/dist/crypto/GuidGenerator.cjs.map +1 -1
  91. package/dist/crypto/GuidGenerator.mjs +1 -1
  92. package/dist/crypto/GuidGenerator.mjs.map +1 -1
  93. package/dist/crypto/HashUtils.cjs +1 -1
  94. package/dist/crypto/HashUtils.cjs.map +1 -1
  95. package/dist/crypto/HashUtils.mjs +1 -1
  96. package/dist/crypto/HashUtils.mjs.map +1 -1
  97. package/dist/crypto/PkceGenerator.cjs +1 -1
  98. package/dist/crypto/PkceGenerator.cjs.map +1 -1
  99. package/dist/crypto/PkceGenerator.mjs +1 -1
  100. package/dist/crypto/PkceGenerator.mjs.map +1 -1
  101. package/dist/error/NodeAuthError.cjs +1 -1
  102. package/dist/error/NodeAuthError.cjs.map +1 -1
  103. package/dist/error/NodeAuthError.mjs +1 -1
  104. package/dist/error/NodeAuthError.mjs.map +1 -1
  105. package/dist/index.cjs +1 -1
  106. package/dist/index.d.ts +32 -32
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.mjs +1 -1
  109. package/dist/internals.cjs +1 -1
  110. package/dist/internals.cjs.map +1 -1
  111. package/dist/internals.d.ts +2 -2
  112. package/dist/internals.d.ts.map +1 -1
  113. package/dist/internals.mjs +1 -1
  114. package/dist/internals.mjs.map +1 -1
  115. package/dist/network/HttpClient.cjs +10 -9
  116. package/dist/network/HttpClient.cjs.map +1 -1
  117. package/dist/network/HttpClient.d.ts.map +1 -1
  118. package/dist/network/HttpClient.mjs +3 -2
  119. package/dist/network/HttpClient.mjs.map +1 -1
  120. package/dist/network/LoopbackClient.cjs +2 -2
  121. package/dist/network/LoopbackClient.cjs.map +1 -1
  122. package/dist/network/LoopbackClient.d.ts +1 -1
  123. package/dist/network/LoopbackClient.d.ts.map +1 -1
  124. package/dist/network/LoopbackClient.mjs +3 -3
  125. package/dist/network/LoopbackClient.mjs.map +1 -1
  126. package/dist/packageMetadata.cjs +2 -2
  127. package/dist/packageMetadata.cjs.map +1 -1
  128. package/dist/packageMetadata.d.ts +1 -1
  129. package/dist/packageMetadata.mjs +2 -2
  130. package/dist/packageMetadata.mjs.map +1 -1
  131. package/dist/request/InteractiveRequest.d.ts +2 -2
  132. package/dist/request/InteractiveRequest.d.ts.map +1 -1
  133. package/dist/utils/Constants.cjs +1 -11
  134. package/dist/utils/Constants.cjs.map +1 -1
  135. package/dist/utils/Constants.d.ts +0 -10
  136. package/dist/utils/Constants.d.ts.map +1 -1
  137. package/dist/utils/Constants.mjs +2 -11
  138. package/dist/utils/Constants.mjs.map +1 -1
  139. package/dist/utils/EncodingUtils.cjs +1 -1
  140. package/dist/utils/EncodingUtils.cjs.map +1 -1
  141. package/dist/utils/EncodingUtils.mjs +1 -1
  142. package/dist/utils/EncodingUtils.mjs.map +1 -1
  143. package/dist/utils/NetworkUtils.cjs +1 -1
  144. package/dist/utils/NetworkUtils.cjs.map +1 -1
  145. package/dist/utils/NetworkUtils.mjs +1 -1
  146. package/dist/utils/NetworkUtils.mjs.map +1 -1
  147. package/package.json +8 -5
  148. package/src/cache/ITokenCache.ts +24 -0
  149. package/src/cache/NodeStorage.ts +533 -0
  150. package/src/cache/TokenCache.ts +358 -0
  151. package/src/cache/distributed/DistributedCachePlugin.ts +56 -0
  152. package/src/cache/distributed/ICacheClient.ts +23 -0
  153. package/src/cache/distributed/IPartitionManager.ts +35 -0
  154. package/src/cache/serializer/Deserializer.ts +218 -0
  155. package/src/cache/serializer/Serializer.ts +173 -0
  156. package/src/cache/serializer/SerializerTypes.ts +121 -0
  157. package/src/client/ClientApplication.ts +595 -0
  158. package/src/client/ClientAssertion.ts +160 -0
  159. package/src/client/ClientCredentialClient.ts +348 -0
  160. package/src/client/ConfidentialClientApplication.ts +261 -0
  161. package/src/client/DeviceCodeClient.ts +360 -0
  162. package/src/client/IConfidentialClientApplication.ts +72 -0
  163. package/src/client/IPublicClientApplication.ts +72 -0
  164. package/src/client/OnBehalfOfClient.ts +361 -0
  165. package/src/client/PublicClientApplication.ts +283 -0
  166. package/src/client/UsernamePasswordClient.ts +180 -0
  167. package/src/config/Configuration.ts +201 -0
  168. package/src/crypto/CryptoProvider.ts +98 -0
  169. package/src/crypto/GuidGenerator.ts +28 -0
  170. package/src/crypto/HashUtils.ts +17 -0
  171. package/src/crypto/PkceGenerator.ts +63 -0
  172. package/src/error/NodeAuthError.ts +117 -0
  173. package/src/index.ts +121 -0
  174. package/src/internals.ts +12 -0
  175. package/src/network/HttpClient.ts +425 -0
  176. package/src/network/ILoopbackClient.ts +19 -0
  177. package/src/network/LoopbackClient.ts +126 -0
  178. package/src/packageMetadata.ts +3 -0
  179. package/src/request/AuthorizationCodeRequest.ts +39 -0
  180. package/src/request/AuthorizationUrlRequest.ts +50 -0
  181. package/src/request/ClientCredentialRequest.ts +29 -0
  182. package/src/request/DeviceCodeRequest.ts +34 -0
  183. package/src/request/InteractiveRequest.ts +39 -0
  184. package/src/request/OnBehalfOfRequest.ts +30 -0
  185. package/src/request/RefreshTokenRequest.ts +34 -0
  186. package/src/request/SignOutRequest.ts +11 -0
  187. package/src/request/SilentFlowRequest.ts +32 -0
  188. package/src/request/UsernamePasswordRequest.ts +36 -0
  189. package/src/utils/Constants.ts +103 -0
  190. package/src/utils/EncodingUtils.ts +50 -0
  191. package/src/utils/NetworkUtils.ts +49 -0
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { CommonClientCredentialRequest } from "@azure/msal-common";
7
+
8
+ /**
9
+ * CommonClientCredentialRequest
10
+ * - scopes - Array of scopes the application is requesting access to. Typically contains only the .default scope for a single resource. See: https://learn.microsoft.com/azure/active-directory/develop/scopes-oidc#the-default-scope
11
+ * - authority - URL of the authority, the security token service (STS) from which MSAL will acquire tokens.
12
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
13
+ * - skipCache - Skip token cache lookup and force request to authority to get a a new token. Defaults to false.
14
+ * - clientAssertion - A Base64Url-encoded signed JWT assertion string used in the Client Credential flow
15
+ * - tokenQueryParameters - String to string map of custom query parameters added to the /token call
16
+ * @public
17
+ */
18
+ export type ClientCredentialRequest = Partial<
19
+ Omit<
20
+ CommonClientCredentialRequest,
21
+ | "resourceRequestMethod"
22
+ | "resourceRequestUri"
23
+ | "requestedClaimsHash"
24
+ | "clientAssertion"
25
+ | "storeInCache"
26
+ >
27
+ > & {
28
+ clientAssertion?: string;
29
+ };
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ CommonDeviceCodeRequest,
8
+ DeviceCodeResponse,
9
+ } from "@azure/msal-common";
10
+
11
+ /**
12
+ * Parameters for Oauth2 device code flow.
13
+ * - scopes - Array of scopes the application is requesting access to.
14
+ * - authority: - URL of the authority, the security token service (STS) from which MSAL will acquire tokens. If authority is set on client application object, this will override that value. Overriding the value will cause for authority validation to happen each time. If the same authority will be used for all request, set on the application object instead of the requests.
15
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
16
+ * - deviceCodeCallback - Callback containing device code response. Message should be shown to end user. End user can then navigate to the verification_uri, input the user_code, and input credentials.
17
+ * - cancel - Boolean to cancel polling of device code endpoint. While the user authenticates on a separate device, MSAL polls the the token endpoint of security token service for the interval specified in the device code response (usually 15 minutes). To stop polling and cancel the request, set cancel=true.
18
+ * - extraQueryParameters - String to string map of custom query parameters added to the query string
19
+ * @public
20
+ */
21
+ export type DeviceCodeRequest = Partial<
22
+ Omit<
23
+ CommonDeviceCodeRequest,
24
+ | "scopes"
25
+ | "deviceCodeCallback"
26
+ | "resourceRequestMethod"
27
+ | "resourceRequestUri"
28
+ | "requestedClaimsHash"
29
+ | "storeInCache"
30
+ >
31
+ > & {
32
+ scopes: Array<string>;
33
+ deviceCodeCallback: (response: DeviceCodeResponse) => void;
34
+ };
@@ -0,0 +1,39 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { ILoopbackClient } from "../network/ILoopbackClient.js";
7
+ import { AuthorizationUrlRequest } from "./AuthorizationUrlRequest.js";
8
+
9
+ /**
10
+ * Request object passed by user to configure acquireTokenInteractive API
11
+ *
12
+ * - openBrowser - Function to open a browser instance on user's system.
13
+ * - scopes - Array of scopes the application is requesting access to.
14
+ * - successTemplate: - Template to be displayed on the opened browser instance upon successful token acquisition.
15
+ * - errorTemplate - Template to be displayed on the opened browser instance upon token acquisition failure.
16
+ * - windowHandle - Used in native broker flows to properly parent the native broker window
17
+ * - loopbackClient - Custom implementation for a loopback server to listen for authorization code response.
18
+ * @public
19
+ */
20
+ export type InteractiveRequest = Pick<
21
+ AuthorizationUrlRequest,
22
+ | "authority"
23
+ | "correlationId"
24
+ | "claims"
25
+ | "azureCloudOptions"
26
+ | "account"
27
+ | "extraQueryParameters"
28
+ | "tokenQueryParameters"
29
+ | "extraScopesToConsent"
30
+ | "loginHint"
31
+ | "prompt"
32
+ > & {
33
+ openBrowser: (url: string) => Promise<void>;
34
+ scopes?: Array<string>;
35
+ successTemplate?: string;
36
+ errorTemplate?: string;
37
+ windowHandle?: Buffer; // Relevant only to brokered requests
38
+ loopbackClient?: ILoopbackClient;
39
+ };
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { CommonOnBehalfOfRequest } from "@azure/msal-common";
7
+
8
+ /**
9
+ * - scopes - Array of scopes the application is requesting access to.
10
+ * - authority - URL of the authority, the security token service (STS) from which MSAL will acquire tokens.
11
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
12
+ * - oboAssertion - The access token that was sent to the middle-tier API. This token must have an audience of the app making this OBO request.
13
+ * - skipCache - Skip token cache lookup and force request to authority to get a a new token. Defaults to false.
14
+ * - tokenQueryParameters - String to string map of custom query parameters added to the /token call
15
+ * @public
16
+ */
17
+ export type OnBehalfOfRequest = Partial<
18
+ Omit<
19
+ CommonOnBehalfOfRequest,
20
+ | "oboAssertion"
21
+ | "scopes"
22
+ | "resourceRequestMethod"
23
+ | "resourceRequestUri"
24
+ | "requestedClaimsHash"
25
+ | "storeInCache"
26
+ >
27
+ > & {
28
+ oboAssertion: string;
29
+ scopes: Array<string>;
30
+ };
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { CommonRefreshTokenRequest } from "@azure/msal-common";
7
+
8
+ /**
9
+ * CommonRefreshTokenRequest
10
+ * - scopes - Array of scopes the application is requesting access to.
11
+ * - claims - A stringified claims request which will be added to all /authorize and /token calls
12
+ * - authority - URL of the authority, the security token service (STS) from which MSAL will acquire tokens.
13
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
14
+ * - refreshToken - A refresh token returned from a previous request to the Identity provider.
15
+ * - tokenQueryParameters - String to string map of custom query parameters added to the /token call
16
+ * - forceCache - Force MSAL to cache a refresh token flow response when there is no account in the cache. Used for migration scenarios.
17
+ * @public
18
+ */
19
+ export type RefreshTokenRequest = Partial<
20
+ Omit<
21
+ CommonRefreshTokenRequest,
22
+ | "scopes"
23
+ | "refreshToken"
24
+ | "authenticationScheme"
25
+ | "resourceRequestMethod"
26
+ | "resourceRequestUri"
27
+ | "requestedClaimsHash"
28
+ | "storeInCache"
29
+ >
30
+ > & {
31
+ scopes: Array<string>;
32
+ refreshToken: string;
33
+ forceCache?: boolean;
34
+ };
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { AccountInfo } from "@azure/msal-common";
7
+
8
+ export type SignOutRequest = {
9
+ account: AccountInfo;
10
+ correlationId?: string;
11
+ };
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { AccountInfo, CommonSilentFlowRequest } from "@azure/msal-common";
7
+
8
+ /**
9
+ * SilentFlow parameters passed by the user to retrieve credentials silently
10
+ * - scopes - Array of scopes the application is requesting access to.
11
+ * - claims - A stringified claims request which will be added to all /authorize and /token calls. When included on a silent request, cache lookup will be skipped and token will be refreshed.
12
+ * - authority - Url of the authority which the application acquires tokens from.
13
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
14
+ * - tokenQueryParameters - String to string map of custom query parameters added to the /token call
15
+ * - account - Account entity to lookup the credentials.
16
+ * - forceRefresh - Forces silent requests to make network calls if true.
17
+ * @public
18
+ */
19
+ export type SilentFlowRequest = Partial<
20
+ Omit<
21
+ CommonSilentFlowRequest,
22
+ | "account"
23
+ | "scopes"
24
+ | "resourceRequestMethod"
25
+ | "resourceRequestUri"
26
+ | "requestedClaimsHash"
27
+ | "storeInCache"
28
+ >
29
+ > & {
30
+ account: AccountInfo;
31
+ scopes: Array<string>;
32
+ };
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { CommonUsernamePasswordRequest } from "@azure/msal-common";
7
+
8
+ /**
9
+ * UsernamePassword parameters passed by the user to retrieve credentials
10
+ * Note: The latest OAuth 2.0 Security Best Current Practice disallows the password grant entirely. This flow is added for internal testing.
11
+ *
12
+ * - scopes - Array of scopes the application is requesting access to.
13
+ * - claims - A stringified claims request which will be added to all /authorize and /token calls. When included on a silent request, cache lookup will be skipped and token will be refreshed.
14
+ * - authority - Url of the authority which the application acquires tokens from.
15
+ * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
16
+ * - username - username of the client
17
+ * - password - credentials
18
+ * - tokenQueryParameters - String to string map of custom query parameters added to the /token call
19
+ * @public
20
+ */
21
+ export type UsernamePasswordRequest = Partial<
22
+ Omit<
23
+ CommonUsernamePasswordRequest,
24
+ | "scopes"
25
+ | "resourceRequestMethod"
26
+ | "resourceRequestUri"
27
+ | "username"
28
+ | "password"
29
+ | "requestedClaimsHash"
30
+ | "storeInCache"
31
+ >
32
+ > & {
33
+ scopes: Array<string>;
34
+ username: string;
35
+ password: string;
36
+ };
@@ -0,0 +1,103 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /**
7
+ * http methods
8
+ */
9
+ export const HttpMethod = {
10
+ GET: "get",
11
+ POST: "post",
12
+ } as const;
13
+ export type HttpMethod = (typeof HttpMethod)[keyof typeof HttpMethod];
14
+
15
+ export const ProxyStatus = {
16
+ SUCCESS_RANGE_START: 200,
17
+ SUCCESS_RANGE_END: 299,
18
+ SERVER_ERROR: 500,
19
+ } as const;
20
+ export type ProxyStatus = (typeof ProxyStatus)[keyof typeof ProxyStatus];
21
+
22
+ /**
23
+ * Constants used for region discovery
24
+ */
25
+ export const REGION_ENVIRONMENT_VARIABLE = "REGION_NAME";
26
+
27
+ /**
28
+ * Constant used for PKCE
29
+ */
30
+ export const RANDOM_OCTET_SIZE = 32;
31
+
32
+ /**
33
+ * Constants used in PKCE
34
+ */
35
+ export const Hash = {
36
+ SHA256: "sha256",
37
+ };
38
+
39
+ /**
40
+ * Constants for encoding schemes
41
+ */
42
+ export const CharSet = {
43
+ CV_CHARSET:
44
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",
45
+ };
46
+
47
+ /**
48
+ * Cache Constants
49
+ */
50
+ export const CACHE = {
51
+ FILE_CACHE: "fileCache",
52
+ EXTENSION_LIB: "extenstion_library",
53
+ };
54
+
55
+ /**
56
+ * Constants
57
+ */
58
+ export const Constants = {
59
+ MSAL_SKU: "msal.js.node",
60
+ JWT_BEARER_ASSERTION_TYPE:
61
+ "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
62
+ AUTHORIZATION_PENDING: "authorization_pending",
63
+ HTTP_PROTOCOL: "http://",
64
+ LOCALHOST: "localhost",
65
+ };
66
+
67
+ /**
68
+ * API Codes for Telemetry purposes.
69
+ * Before adding a new code you must claim it in the MSAL Telemetry tracker as these number spaces are shared across all MSALs
70
+ * 0-99 Silent Flow
71
+ * 600-699 Device Code Flow
72
+ * 800-899 Auth Code Flow
73
+ */
74
+ export const ApiId = {
75
+ acquireTokenSilent: 62,
76
+ acquireTokenByUsernamePassword: 371,
77
+ acquireTokenByDeviceCode: 671,
78
+ acquireTokenByClientCredential: 771,
79
+ acquireTokenByCode: 871,
80
+ acquireTokenByRefreshToken: 872,
81
+ };
82
+ export type ApiId = (typeof ApiId)[keyof typeof ApiId];
83
+
84
+ /**
85
+ * JWT constants
86
+ */
87
+ export const JwtConstants = {
88
+ ALGORITHM: "alg",
89
+ RSA_256: "RS256",
90
+ X5T: "x5t",
91
+ X5C: "x5c",
92
+ AUDIENCE: "aud",
93
+ EXPIRATION_TIME: "exp",
94
+ ISSUER: "iss",
95
+ SUBJECT: "sub",
96
+ NOT_BEFORE: "nbf",
97
+ JWT_ID: "jti",
98
+ };
99
+
100
+ export const LOOPBACK_SERVER_CONSTANTS = {
101
+ INTERVAL_MS: 100,
102
+ TIMEOUT_MS: 5000,
103
+ };
@@ -0,0 +1,50 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { Constants } from "@azure/msal-common";
7
+
8
+ export class EncodingUtils {
9
+ /**
10
+ * 'utf8': Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.
11
+ * 'base64': Base64 encoding.
12
+ *
13
+ * @param str text
14
+ */
15
+ static base64Encode(str: string, encoding?: BufferEncoding): string {
16
+ return Buffer.from(str, encoding).toString("base64");
17
+ }
18
+
19
+ /**
20
+ * encode a URL
21
+ * @param str
22
+ */
23
+ static base64EncodeUrl(str: string, encoding?: BufferEncoding): string {
24
+ return EncodingUtils.base64Encode(str, encoding)
25
+ .replace(/=/g, Constants.EMPTY_STRING)
26
+ .replace(/\+/g, "-")
27
+ .replace(/\//g, "_");
28
+ }
29
+
30
+ /**
31
+ * 'utf8': Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.
32
+ * 'base64': Base64 encoding.
33
+ *
34
+ * @param base64Str Base64 encoded text
35
+ */
36
+ static base64Decode(base64Str: string): string {
37
+ return Buffer.from(base64Str, "base64").toString("utf8");
38
+ }
39
+
40
+ /**
41
+ * @param base64Str Base64 encoded Url
42
+ */
43
+ static base64DecodeUrl(base64Str: string): string {
44
+ let str = base64Str.replace(/-/g, "+").replace(/_/g, "/");
45
+ while (str.length % 4) {
46
+ str += "=";
47
+ }
48
+ return EncodingUtils.base64Decode(str);
49
+ }
50
+ }
@@ -0,0 +1,49 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { NetworkResponse, UrlToHttpRequestOptions } from "@azure/msal-common";
7
+
8
+ export class NetworkUtils {
9
+ static getNetworkResponse<T>(
10
+ headers: Record<string, string>,
11
+ body: T,
12
+ statusCode: number
13
+ ): NetworkResponse<T> {
14
+ return {
15
+ headers: headers,
16
+ body: body,
17
+ status: statusCode,
18
+ };
19
+ }
20
+
21
+ /*
22
+ * Utility function that converts a URL object into an ordinary options object as expected by the
23
+ * http.request and https.request APIs.
24
+ * https://github.com/nodejs/node/blob/main/lib/internal/url.js#L1090
25
+ */
26
+ static urlToHttpOptions(url: URL): UrlToHttpRequestOptions {
27
+ const options: UrlToHttpRequestOptions = {
28
+ protocol: url.protocol,
29
+ hostname:
30
+ url.hostname && url.hostname.startsWith("[")
31
+ ? url.hostname.slice(1, -1)
32
+ : url.hostname,
33
+ hash: url.hash,
34
+ search: url.search,
35
+ pathname: url.pathname,
36
+ path: `${url.pathname || ""}${url.search || ""}`,
37
+ href: url.href,
38
+ };
39
+ if (url.port !== "") {
40
+ options.port = Number(url.port);
41
+ }
42
+ if (url.username || url.password) {
43
+ options.auth = `${decodeURIComponent(
44
+ url.username
45
+ )}:${decodeURIComponent(url.password)}`;
46
+ }
47
+ return options;
48
+ }
49
+ }