@azure/msal-node 2.0.2 → 2.2.0-alpha.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 (218) hide show
  1. package/README.md +3 -1
  2. package/dist/cache/ITokenCache.d.ts +15 -15
  3. package/dist/cache/NodeStorage.cjs +401 -401
  4. package/dist/cache/NodeStorage.cjs.map +1 -1
  5. package/dist/cache/NodeStorage.d.ts +182 -182
  6. package/dist/cache/NodeStorage.d.ts.map +1 -1
  7. package/dist/cache/NodeStorage.mjs +401 -401
  8. package/dist/cache/NodeStorage.mjs.map +1 -1
  9. package/dist/cache/TokenCache.cjs +265 -269
  10. package/dist/cache/TokenCache.cjs.map +1 -1
  11. package/dist/cache/TokenCache.d.ts +90 -90
  12. package/dist/cache/TokenCache.d.ts.map +1 -1
  13. package/dist/cache/TokenCache.mjs +266 -270
  14. package/dist/cache/TokenCache.mjs.map +1 -1
  15. package/dist/cache/distributed/DistributedCachePlugin.cjs +26 -26
  16. package/dist/cache/distributed/DistributedCachePlugin.cjs.map +1 -1
  17. package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
  18. package/dist/cache/distributed/DistributedCachePlugin.d.ts.map +1 -1
  19. package/dist/cache/distributed/DistributedCachePlugin.mjs +26 -26
  20. package/dist/cache/distributed/DistributedCachePlugin.mjs.map +1 -1
  21. package/dist/cache/distributed/ICacheClient.d.ts +17 -17
  22. package/dist/cache/distributed/IPartitionManager.d.ts +28 -28
  23. package/dist/cache/serializer/Deserializer.cjs +173 -175
  24. package/dist/cache/serializer/Deserializer.cjs.map +1 -1
  25. package/dist/cache/serializer/Deserializer.d.ts +42 -42
  26. package/dist/cache/serializer/Deserializer.d.ts.map +1 -1
  27. package/dist/cache/serializer/Deserializer.mjs +174 -176
  28. package/dist/cache/serializer/Deserializer.mjs.map +1 -1
  29. package/dist/cache/serializer/Serializer.cjs +134 -134
  30. package/dist/cache/serializer/Serializer.cjs.map +1 -1
  31. package/dist/cache/serializer/Serializer.d.ts +39 -39
  32. package/dist/cache/serializer/Serializer.d.ts.map +1 -1
  33. package/dist/cache/serializer/Serializer.mjs +134 -134
  34. package/dist/cache/serializer/Serializer.mjs.map +1 -1
  35. package/dist/cache/serializer/SerializerTypes.d.ts +101 -101
  36. package/dist/client/ClientApplication.cjs +333 -333
  37. package/dist/client/ClientApplication.cjs.map +1 -1
  38. package/dist/client/ClientApplication.d.ts +142 -142
  39. package/dist/client/ClientApplication.d.ts.map +1 -1
  40. package/dist/client/ClientApplication.mjs +334 -334
  41. package/dist/client/ClientApplication.mjs.map +1 -1
  42. package/dist/client/ClientAssertion.cjs +116 -116
  43. package/dist/client/ClientAssertion.cjs.map +1 -1
  44. package/dist/client/ClientAssertion.d.ts +46 -46
  45. package/dist/client/ClientAssertion.d.ts.map +1 -1
  46. package/dist/client/ClientAssertion.mjs +117 -117
  47. package/dist/client/ClientAssertion.mjs.map +1 -1
  48. package/dist/client/ClientCredentialClient.cjs +189 -168
  49. package/dist/client/ClientCredentialClient.cjs.map +1 -1
  50. package/dist/client/ClientCredentialClient.d.ts +33 -33
  51. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  52. package/dist/client/ClientCredentialClient.mjs +190 -169
  53. package/dist/client/ClientCredentialClient.mjs.map +1 -1
  54. package/dist/client/ConfidentialClientApplication.cjs +163 -164
  55. package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
  56. package/dist/client/ConfidentialClientApplication.d.ts +58 -58
  57. package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
  58. package/dist/client/ConfidentialClientApplication.mjs +164 -165
  59. package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
  60. package/dist/client/DeviceCodeClient.cjs +207 -207
  61. package/dist/client/DeviceCodeClient.cjs.map +1 -1
  62. package/dist/client/DeviceCodeClient.d.ts +53 -53
  63. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  64. package/dist/client/DeviceCodeClient.mjs +208 -208
  65. package/dist/client/DeviceCodeClient.mjs.map +1 -1
  66. package/dist/client/IConfidentialClientApplication.d.ts +39 -39
  67. package/dist/client/IConfidentialClientApplication.d.ts.map +1 -1
  68. package/dist/client/IPublicClientApplication.d.ts +42 -42
  69. package/dist/client/IPublicClientApplication.d.ts.map +1 -1
  70. package/dist/client/OnBehalfOfClient.cjs +203 -204
  71. package/dist/client/OnBehalfOfClient.cjs.map +1 -1
  72. package/dist/client/OnBehalfOfClient.d.ts +47 -47
  73. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  74. package/dist/client/OnBehalfOfClient.mjs +204 -205
  75. package/dist/client/OnBehalfOfClient.mjs.map +1 -1
  76. package/dist/client/PublicClientApplication.cjs +229 -175
  77. package/dist/client/PublicClientApplication.cjs.map +1 -1
  78. package/dist/client/PublicClientApplication.d.ts +71 -65
  79. package/dist/client/PublicClientApplication.d.ts.map +1 -1
  80. package/dist/client/PublicClientApplication.mjs +232 -178
  81. package/dist/client/PublicClientApplication.mjs.map +1 -1
  82. package/dist/client/UsernamePasswordClient.cjs +95 -95
  83. package/dist/client/UsernamePasswordClient.cjs.map +1 -1
  84. package/dist/client/UsernamePasswordClient.d.ts +25 -25
  85. package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
  86. package/dist/client/UsernamePasswordClient.mjs +95 -95
  87. package/dist/client/UsernamePasswordClient.mjs.map +1 -1
  88. package/dist/config/Configuration.cjs +72 -72
  89. package/dist/config/Configuration.cjs.map +1 -1
  90. package/dist/config/Configuration.d.ts +107 -107
  91. package/dist/config/Configuration.mjs +72 -72
  92. package/dist/config/Configuration.mjs.map +1 -1
  93. package/dist/crypto/CryptoProvider.cjs +75 -75
  94. package/dist/crypto/CryptoProvider.cjs.map +1 -1
  95. package/dist/crypto/CryptoProvider.d.ts +52 -52
  96. package/dist/crypto/CryptoProvider.mjs +75 -75
  97. package/dist/crypto/CryptoProvider.mjs.map +1 -1
  98. package/dist/crypto/GuidGenerator.cjs +22 -22
  99. package/dist/crypto/GuidGenerator.cjs.map +1 -1
  100. package/dist/crypto/GuidGenerator.d.ts +14 -14
  101. package/dist/crypto/GuidGenerator.mjs +22 -22
  102. package/dist/crypto/GuidGenerator.mjs.map +1 -1
  103. package/dist/crypto/HashUtils.cjs +13 -13
  104. package/dist/crypto/HashUtils.cjs.map +1 -1
  105. package/dist/crypto/HashUtils.d.ts +8 -8
  106. package/dist/crypto/HashUtils.mjs +13 -13
  107. package/dist/crypto/HashUtils.mjs.map +1 -1
  108. package/dist/crypto/PkceGenerator.cjs +49 -49
  109. package/dist/crypto/PkceGenerator.cjs.map +1 -1
  110. package/dist/crypto/PkceGenerator.d.ts +22 -22
  111. package/dist/crypto/PkceGenerator.mjs +49 -49
  112. package/dist/crypto/PkceGenerator.mjs.map +1 -1
  113. package/dist/error/NodeAuthError.cjs +85 -85
  114. package/dist/error/NodeAuthError.cjs.map +1 -1
  115. package/dist/error/NodeAuthError.d.ts +65 -65
  116. package/dist/error/NodeAuthError.mjs +85 -85
  117. package/dist/error/NodeAuthError.mjs.map +1 -1
  118. package/dist/index.cjs +17 -1
  119. package/dist/index.cjs.map +1 -1
  120. package/dist/index.d.ts +42 -42
  121. package/dist/index.d.ts.map +1 -1
  122. package/dist/index.mjs +2 -2
  123. package/dist/internals.cjs +8 -8
  124. package/dist/internals.cjs.map +1 -1
  125. package/dist/internals.d.ts +6 -6
  126. package/dist/internals.d.ts.map +1 -1
  127. package/dist/internals.mjs +8 -8
  128. package/dist/internals.mjs.map +1 -1
  129. package/dist/network/HttpClient.cjs +277 -276
  130. package/dist/network/HttpClient.cjs.map +1 -1
  131. package/dist/network/HttpClient.d.ts +25 -25
  132. package/dist/network/HttpClient.d.ts.map +1 -1
  133. package/dist/network/HttpClient.mjs +278 -277
  134. package/dist/network/HttpClient.mjs.map +1 -1
  135. package/dist/network/ILoopbackClient.d.ts +10 -10
  136. package/dist/network/LoopbackClient.cjs +75 -84
  137. package/dist/network/LoopbackClient.cjs.map +1 -1
  138. package/dist/network/LoopbackClient.d.ts +21 -21
  139. package/dist/network/LoopbackClient.d.ts.map +1 -1
  140. package/dist/network/LoopbackClient.mjs +77 -86
  141. package/dist/network/LoopbackClient.mjs.map +1 -1
  142. package/dist/packageMetadata.cjs +4 -4
  143. package/dist/packageMetadata.cjs.map +1 -1
  144. package/dist/packageMetadata.d.ts +2 -2
  145. package/dist/packageMetadata.mjs +4 -4
  146. package/dist/packageMetadata.mjs.map +1 -1
  147. package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
  148. package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
  149. package/dist/request/ClientCredentialRequest.d.ts +14 -14
  150. package/dist/request/DeviceCodeRequest.d.ts +15 -15
  151. package/dist/request/InteractiveRequest.d.ts +22 -22
  152. package/dist/request/InteractiveRequest.d.ts.map +1 -1
  153. package/dist/request/OnBehalfOfRequest.d.ts +14 -14
  154. package/dist/request/RefreshTokenRequest.d.ts +17 -17
  155. package/dist/request/SignOutRequest.d.ts +5 -5
  156. package/dist/request/SilentFlowRequest.d.ts +16 -16
  157. package/dist/request/UsernamePasswordRequest.d.ts +19 -19
  158. package/dist/utils/Constants.cjs +80 -90
  159. package/dist/utils/Constants.cjs.map +1 -1
  160. package/dist/utils/Constants.d.ts +86 -96
  161. package/dist/utils/Constants.d.ts.map +1 -1
  162. package/dist/utils/Constants.mjs +81 -90
  163. package/dist/utils/Constants.mjs.map +1 -1
  164. package/dist/utils/EncodingUtils.cjs +44 -44
  165. package/dist/utils/EncodingUtils.cjs.map +1 -1
  166. package/dist/utils/EncodingUtils.d.ts +26 -26
  167. package/dist/utils/EncodingUtils.mjs +44 -44
  168. package/dist/utils/EncodingUtils.mjs.map +1 -1
  169. package/dist/utils/NetworkUtils.cjs +38 -38
  170. package/dist/utils/NetworkUtils.cjs.map +1 -1
  171. package/dist/utils/NetworkUtils.d.ts +5 -5
  172. package/dist/utils/NetworkUtils.mjs +38 -38
  173. package/dist/utils/NetworkUtils.mjs.map +1 -1
  174. package/package.json +8 -5
  175. package/src/cache/ITokenCache.ts +24 -0
  176. package/src/cache/NodeStorage.ts +533 -0
  177. package/src/cache/TokenCache.ts +358 -0
  178. package/src/cache/distributed/DistributedCachePlugin.ts +56 -0
  179. package/src/cache/distributed/ICacheClient.ts +23 -0
  180. package/src/cache/distributed/IPartitionManager.ts +35 -0
  181. package/src/cache/serializer/Deserializer.ts +218 -0
  182. package/src/cache/serializer/Serializer.ts +173 -0
  183. package/src/cache/serializer/SerializerTypes.ts +121 -0
  184. package/src/client/ClientApplication.ts +596 -0
  185. package/src/client/ClientAssertion.ts +165 -0
  186. package/src/client/ClientCredentialClient.ts +346 -0
  187. package/src/client/ConfidentialClientApplication.ts +268 -0
  188. package/src/client/DeviceCodeClient.ts +369 -0
  189. package/src/client/IConfidentialClientApplication.ts +72 -0
  190. package/src/client/IPublicClientApplication.ts +72 -0
  191. package/src/client/OnBehalfOfClient.ts +368 -0
  192. package/src/client/PublicClientApplication.ts +339 -0
  193. package/src/client/UsernamePasswordClient.ts +180 -0
  194. package/src/config/Configuration.ts +201 -0
  195. package/src/crypto/CryptoProvider.ts +98 -0
  196. package/src/crypto/GuidGenerator.ts +28 -0
  197. package/src/crypto/HashUtils.ts +17 -0
  198. package/src/crypto/PkceGenerator.ts +63 -0
  199. package/src/error/NodeAuthError.ts +117 -0
  200. package/src/index.ts +125 -0
  201. package/src/internals.ts +12 -0
  202. package/src/network/HttpClient.ts +425 -0
  203. package/src/network/ILoopbackClient.ts +19 -0
  204. package/src/network/LoopbackClient.ts +110 -0
  205. package/src/packageMetadata.ts +3 -0
  206. package/src/request/AuthorizationCodeRequest.ts +39 -0
  207. package/src/request/AuthorizationUrlRequest.ts +50 -0
  208. package/src/request/ClientCredentialRequest.ts +29 -0
  209. package/src/request/DeviceCodeRequest.ts +34 -0
  210. package/src/request/InteractiveRequest.ts +39 -0
  211. package/src/request/OnBehalfOfRequest.ts +30 -0
  212. package/src/request/RefreshTokenRequest.ts +34 -0
  213. package/src/request/SignOutRequest.ts +11 -0
  214. package/src/request/SilentFlowRequest.ts +32 -0
  215. package/src/request/UsernamePasswordRequest.ts +36 -0
  216. package/src/utils/Constants.ts +103 -0
  217. package/src/utils/EncodingUtils.ts +50 -0
  218. package/src/utils/NetworkUtils.ts +49 -0
@@ -1,125 +1,125 @@
1
- /*! @azure/msal-node v2.0.2 2023-08-18 */
1
+ /*! @azure/msal-node v2.2.0-alpha.0 2023-09-20 */
2
2
  'use strict';
3
3
  import jwt from 'jsonwebtoken';
4
- import { ClientAuthError, TimeUtils, Constants } from '@azure/msal-common';
4
+ import { createClientAuthError, ClientAuthErrorCodes, TimeUtils, Constants } from '@azure/msal-common';
5
5
  import { EncodingUtils } from '../utils/EncodingUtils.mjs';
6
6
  import { JwtConstants } from '../utils/Constants.mjs';
7
7
 
8
- /*
9
- * Copyright (c) Microsoft Corporation. All rights reserved.
10
- * Licensed under the MIT License.
11
- */
12
- /**
13
- * Client assertion of type jwt-bearer used in confidential client flows
14
- * @public
15
- */
16
- class ClientAssertion {
17
- /**
18
- * Initialize the ClientAssertion class from the clientAssertion passed by the user
19
- * @param assertion - refer https://tools.ietf.org/html/rfc7521
20
- */
21
- static fromAssertion(assertion) {
22
- const clientAssertion = new ClientAssertion();
23
- clientAssertion.jwt = assertion;
24
- return clientAssertion;
25
- }
26
- /**
27
- * Initialize the ClientAssertion class from the certificate passed by the user
28
- * @param thumbprint - identifier of a certificate
29
- * @param privateKey - secret key
30
- * @param publicCertificate - electronic document provided to prove the ownership of the public key
31
- */
32
- static fromCertificate(thumbprint, privateKey, publicCertificate) {
33
- const clientAssertion = new ClientAssertion();
34
- clientAssertion.privateKey = privateKey;
35
- clientAssertion.thumbprint = thumbprint;
36
- if (publicCertificate) {
37
- clientAssertion.publicCertificate =
38
- this.parseCertificate(publicCertificate);
39
- }
40
- return clientAssertion;
41
- }
42
- /**
43
- * Update JWT for certificate based clientAssertion, if passed by the user, uses it as is
44
- * @param cryptoProvider - library's crypto helper
45
- * @param issuer - iss claim
46
- * @param jwtAudience - aud claim
47
- */
48
- getJwt(cryptoProvider, issuer, jwtAudience) {
49
- // if assertion was created from certificate, check if jwt is expired and create new one.
50
- if (this.privateKey && this.thumbprint) {
51
- if (this.jwt &&
52
- !this.isExpired() &&
53
- issuer === this.issuer &&
54
- jwtAudience === this.jwtAudience) {
55
- return this.jwt;
56
- }
57
- return this.createJwt(cryptoProvider, issuer, jwtAudience);
58
- }
59
- /*
60
- * if assertion was created by caller, then we just append it. It is up to the caller to
61
- * ensure that it contains necessary claims and that it is not expired.
62
- */
63
- if (this.jwt) {
64
- return this.jwt;
65
- }
66
- throw ClientAuthError.createInvalidAssertionError();
67
- }
68
- /**
69
- * JWT format and required claims specified: https://tools.ietf.org/html/rfc7523#section-3
70
- */
71
- createJwt(cryptoProvider, issuer, jwtAudience) {
72
- this.issuer = issuer;
73
- this.jwtAudience = jwtAudience;
74
- const issuedAt = TimeUtils.nowSeconds();
75
- this.expirationTime = issuedAt + 600;
76
- const header = {
77
- alg: JwtConstants.RSA_256,
78
- x5t: EncodingUtils.base64EncodeUrl(this.thumbprint, "hex"),
79
- };
80
- if (this.publicCertificate) {
81
- Object.assign(header, {
82
- x5c: this.publicCertificate,
83
- });
84
- }
85
- const payload = {
86
- [JwtConstants.AUDIENCE]: this.jwtAudience,
87
- [JwtConstants.EXPIRATION_TIME]: this.expirationTime,
88
- [JwtConstants.ISSUER]: this.issuer,
89
- [JwtConstants.SUBJECT]: this.issuer,
90
- [JwtConstants.NOT_BEFORE]: issuedAt,
91
- [JwtConstants.JWT_ID]: cryptoProvider.createNewGuid(),
92
- };
93
- this.jwt = jwt.sign(payload, this.privateKey, { header });
94
- return this.jwt;
95
- }
96
- /**
97
- * Utility API to check expiration
98
- */
99
- isExpired() {
100
- return this.expirationTime < TimeUtils.nowSeconds();
101
- }
102
- /**
103
- * Extracts the raw certs from a given certificate string and returns them in an array.
104
- * @param publicCertificate - electronic document provided to prove the ownership of the public key
105
- */
106
- static parseCertificate(publicCertificate) {
107
- /**
108
- * This is regex to identify the certs in a given certificate string.
109
- * We want to look for the contents between the BEGIN and END certificate strings, without the associated newlines.
110
- * The information in parens "(.+?)" is the capture group to represent the cert we want isolated.
111
- * "." means any string character, "+" means match 1 or more times, and "?" means the shortest match.
112
- * The "g" at the end of the regex means search the string globally, and the "s" enables the "." to match newlines.
113
- */
114
- const regexToFindCerts = /-----BEGIN CERTIFICATE-----\r*\n(.+?)\r*\n-----END CERTIFICATE-----/gs;
115
- const certs = [];
116
- let matches;
117
- while ((matches = regexToFindCerts.exec(publicCertificate)) !== null) {
118
- // matches[1] represents the first parens capture group in the regex.
119
- certs.push(matches[1].replace(/\r*\n/g, Constants.EMPTY_STRING));
120
- }
121
- return certs;
122
- }
8
+ /*
9
+ * Copyright (c) Microsoft Corporation. All rights reserved.
10
+ * Licensed under the MIT License.
11
+ */
12
+ /**
13
+ * Client assertion of type jwt-bearer used in confidential client flows
14
+ * @public
15
+ */
16
+ class ClientAssertion {
17
+ /**
18
+ * Initialize the ClientAssertion class from the clientAssertion passed by the user
19
+ * @param assertion - refer https://tools.ietf.org/html/rfc7521
20
+ */
21
+ static fromAssertion(assertion) {
22
+ const clientAssertion = new ClientAssertion();
23
+ clientAssertion.jwt = assertion;
24
+ return clientAssertion;
25
+ }
26
+ /**
27
+ * Initialize the ClientAssertion class from the certificate passed by the user
28
+ * @param thumbprint - identifier of a certificate
29
+ * @param privateKey - secret key
30
+ * @param publicCertificate - electronic document provided to prove the ownership of the public key
31
+ */
32
+ static fromCertificate(thumbprint, privateKey, publicCertificate) {
33
+ const clientAssertion = new ClientAssertion();
34
+ clientAssertion.privateKey = privateKey;
35
+ clientAssertion.thumbprint = thumbprint;
36
+ if (publicCertificate) {
37
+ clientAssertion.publicCertificate =
38
+ this.parseCertificate(publicCertificate);
39
+ }
40
+ return clientAssertion;
41
+ }
42
+ /**
43
+ * Update JWT for certificate based clientAssertion, if passed by the user, uses it as is
44
+ * @param cryptoProvider - library's crypto helper
45
+ * @param issuer - iss claim
46
+ * @param jwtAudience - aud claim
47
+ */
48
+ getJwt(cryptoProvider, issuer, jwtAudience) {
49
+ // if assertion was created from certificate, check if jwt is expired and create new one.
50
+ if (this.privateKey && this.thumbprint) {
51
+ if (this.jwt &&
52
+ !this.isExpired() &&
53
+ issuer === this.issuer &&
54
+ jwtAudience === this.jwtAudience) {
55
+ return this.jwt;
56
+ }
57
+ return this.createJwt(cryptoProvider, issuer, jwtAudience);
58
+ }
59
+ /*
60
+ * if assertion was created by caller, then we just append it. It is up to the caller to
61
+ * ensure that it contains necessary claims and that it is not expired.
62
+ */
63
+ if (this.jwt) {
64
+ return this.jwt;
65
+ }
66
+ throw createClientAuthError(ClientAuthErrorCodes.invalidAssertion);
67
+ }
68
+ /**
69
+ * JWT format and required claims specified: https://tools.ietf.org/html/rfc7523#section-3
70
+ */
71
+ createJwt(cryptoProvider, issuer, jwtAudience) {
72
+ this.issuer = issuer;
73
+ this.jwtAudience = jwtAudience;
74
+ const issuedAt = TimeUtils.nowSeconds();
75
+ this.expirationTime = issuedAt + 600;
76
+ const header = {
77
+ alg: JwtConstants.RSA_256,
78
+ x5t: EncodingUtils.base64EncodeUrl(this.thumbprint, "hex"),
79
+ };
80
+ if (this.publicCertificate) {
81
+ Object.assign(header, {
82
+ x5c: this.publicCertificate,
83
+ });
84
+ }
85
+ const payload = {
86
+ [JwtConstants.AUDIENCE]: this.jwtAudience,
87
+ [JwtConstants.EXPIRATION_TIME]: this.expirationTime,
88
+ [JwtConstants.ISSUER]: this.issuer,
89
+ [JwtConstants.SUBJECT]: this.issuer,
90
+ [JwtConstants.NOT_BEFORE]: issuedAt,
91
+ [JwtConstants.JWT_ID]: cryptoProvider.createNewGuid(),
92
+ };
93
+ this.jwt = jwt.sign(payload, this.privateKey, { header });
94
+ return this.jwt;
95
+ }
96
+ /**
97
+ * Utility API to check expiration
98
+ */
99
+ isExpired() {
100
+ return this.expirationTime < TimeUtils.nowSeconds();
101
+ }
102
+ /**
103
+ * Extracts the raw certs from a given certificate string and returns them in an array.
104
+ * @param publicCertificate - electronic document provided to prove the ownership of the public key
105
+ */
106
+ static parseCertificate(publicCertificate) {
107
+ /**
108
+ * This is regex to identify the certs in a given certificate string.
109
+ * We want to look for the contents between the BEGIN and END certificate strings, without the associated newlines.
110
+ * The information in parens "(.+?)" is the capture group to represent the cert we want isolated.
111
+ * "." means any string character, "+" means match 1 or more times, and "?" means the shortest match.
112
+ * The "g" at the end of the regex means search the string globally, and the "s" enables the "." to match newlines.
113
+ */
114
+ const regexToFindCerts = /-----BEGIN CERTIFICATE-----\r*\n(.+?)\r*\n-----END CERTIFICATE-----/gs;
115
+ const certs = [];
116
+ let matches;
117
+ while ((matches = regexToFindCerts.exec(publicCertificate)) !== null) {
118
+ // matches[1] represents the first parens capture group in the regex.
119
+ certs.push(matches[1].replace(/\r*\n/g, Constants.EMPTY_STRING));
120
+ }
121
+ return certs;
122
+ }
123
123
  }
124
124
 
125
125
  export { ClientAssertion };
@@ -1 +1 @@
1
- {"version":3,"file":"ClientAssertion.mjs","sources":["../../src/client/ClientAssertion.ts"],"sourcesContent":[null],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"ClientAssertion.mjs","sources":["../../src/client/ClientAssertion.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAYA;AAIA;;;;;;;AAWW,sBAAkB;AAEzB;;;AAGG;AACW,IAAA,OAAA,aAAa,CAAC,SAAS,EAAE;AAMvC,QAAA,MAAA,eAAA,GAAA,IAAA,eAAA,EAAA,CAAA;;;;;AAKG;AACW;AAed;;;;;AAKG,QAAA,eAAA,CAAA,UAAA,GAAA,UAAA,CAAA;AACI,QAAA,eACH,CAAA,UAAgB,GAAA,UAChB,CAAA;AA4BJ,QAAA,IAAA,iBAAA,EAAA;;AAEG,gBAAA,IAAA,CAAA,gBAAA,CAAA,iBAAA,CAAA,CAAA;AACH,SAAA;AAkCA,QAAA,OAAA,eAAA,CAAA;;AAEG;AACH;AAIA;;;AAGG;WACW,cAAgB,EAAA,mBAAoB,EAAA;AAoBrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,176 +1,197 @@
1
- /*! @azure/msal-node v2.0.2 2023-08-18 */
1
+ /*! @azure/msal-node v2.2.0-alpha.0 2023-09-20 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
5
5
  var msalCommon = require('@azure/msal-common');
6
6
 
7
- /*
8
- * Copyright (c) Microsoft Corporation. All rights reserved.
9
- * Licensed under the MIT License.
10
- */
11
- /**
12
- * OAuth2.0 client credential grant
13
- */
14
- class ClientCredentialClient extends msalCommon.BaseClient {
15
- constructor(configuration, appTokenProvider) {
16
- super(configuration);
17
- this.appTokenProvider = appTokenProvider;
18
- }
19
- /**
20
- * Public API to acquire a token with ClientCredential Flow for Confidential clients
21
- * @param request
22
- */
23
- async acquireToken(request) {
24
- this.scopeSet = new msalCommon.ScopeSet(request.scopes || []);
25
- if (request.skipCache) {
26
- return await this.executeTokenRequest(request, this.authority);
27
- }
28
- const cachedAuthenticationResult = await this.getCachedAuthenticationResult(request);
29
- if (cachedAuthenticationResult) {
30
- return cachedAuthenticationResult;
31
- }
32
- else {
33
- return await this.executeTokenRequest(request, this.authority);
34
- }
35
- }
36
- /**
37
- * looks up cache if the tokens are cached already
38
- */
39
- async getCachedAuthenticationResult(request) {
40
- // read the user-supplied cache into memory, if applicable
41
- let cacheContext;
42
- if (this.config.serializableCache && this.config.persistencePlugin) {
43
- cacheContext = new msalCommon.TokenCacheContext(this.config.serializableCache, false);
44
- await this.config.persistencePlugin.beforeCacheAccess(cacheContext);
45
- }
46
- const cachedAccessToken = this.readAccessTokenFromCache();
47
- if (this.config.serializableCache &&
48
- this.config.persistencePlugin &&
49
- cacheContext) {
50
- await this.config.persistencePlugin.afterCacheAccess(cacheContext);
51
- }
52
- if (!cachedAccessToken) {
53
- this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.NO_CACHED_ACCESS_TOKEN);
54
- return null;
55
- }
56
- if (msalCommon.TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
57
- this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
58
- return null;
59
- }
60
- return await msalCommon.ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
61
- account: null,
62
- idToken: null,
63
- accessToken: cachedAccessToken,
64
- refreshToken: null,
65
- appMetadata: null,
66
- }, true, request);
67
- }
68
- /**
69
- * Reads access token from the cache
70
- */
71
- readAccessTokenFromCache() {
72
- const accessTokenFilter = {
73
- homeAccountId: msalCommon.Constants.EMPTY_STRING,
74
- environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
75
- credentialType: msalCommon.CredentialType.ACCESS_TOKEN,
76
- clientId: this.config.authOptions.clientId,
77
- realm: this.authority.tenant,
78
- target: msalCommon.ScopeSet.createSearchScopes(this.scopeSet.asArray()),
79
- };
80
- const accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
81
- if (accessTokens.length < 1) {
82
- return null;
83
- }
84
- else if (accessTokens.length > 1) {
85
- throw msalCommon.ClientAuthError.createMultipleMatchingTokensInCacheError();
86
- }
87
- return accessTokens[0];
88
- }
89
- /**
90
- * Makes a network call to request the token from the service
91
- * @param request
92
- * @param authority
93
- */
94
- async executeTokenRequest(request, authority) {
95
- let serverTokenResponse;
96
- let reqTimestamp;
97
- if (this.appTokenProvider) {
98
- this.logger.info("Using appTokenProvider extensibility.");
99
- const appTokenPropviderParameters = {
100
- correlationId: request.correlationId,
101
- tenantId: this.config.authOptions.authority.tenant,
102
- scopes: request.scopes,
103
- claims: request.claims,
104
- };
105
- reqTimestamp = msalCommon.TimeUtils.nowSeconds();
106
- const appTokenProviderResult = await this.appTokenProvider(appTokenPropviderParameters);
107
- serverTokenResponse = {
108
- access_token: appTokenProviderResult.accessToken,
109
- expires_in: appTokenProviderResult.expiresInSeconds,
110
- refresh_in: appTokenProviderResult.refreshInSeconds,
111
- token_type: msalCommon.AuthenticationScheme.BEARER,
112
- };
113
- }
114
- else {
115
- const queryParametersString = this.createTokenQueryParameters(request);
116
- const endpoint = msalCommon.UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
117
- const requestBody = this.createTokenRequestBody(request);
118
- const headers = this.createTokenRequestHeaders();
119
- const thumbprint = {
120
- clientId: this.config.authOptions.clientId,
121
- authority: request.authority,
122
- scopes: request.scopes,
123
- claims: request.claims,
124
- authenticationScheme: request.authenticationScheme,
125
- resourceRequestMethod: request.resourceRequestMethod,
126
- resourceRequestUri: request.resourceRequestUri,
127
- shrClaims: request.shrClaims,
128
- sshKid: request.sshKid,
129
- };
130
- reqTimestamp = msalCommon.TimeUtils.nowSeconds();
131
- const response = await this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint);
132
- serverTokenResponse = response.body;
133
- }
134
- const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
135
- responseHandler.validateTokenResponse(serverTokenResponse);
136
- const tokenResponse = await responseHandler.handleServerTokenResponse(serverTokenResponse, this.authority, reqTimestamp, request);
137
- return tokenResponse;
138
- }
139
- /**
140
- * generate the request to the server in the acceptable format
141
- * @param request
142
- */
143
- createTokenRequestBody(request) {
144
- const parameterBuilder = new msalCommon.RequestParameterBuilder();
145
- parameterBuilder.addClientId(this.config.authOptions.clientId);
146
- parameterBuilder.addScopes(request.scopes, false);
147
- parameterBuilder.addGrantType(msalCommon.GrantType.CLIENT_CREDENTIALS_GRANT);
148
- parameterBuilder.addLibraryInfo(this.config.libraryInfo);
149
- parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
150
- parameterBuilder.addThrottling();
151
- if (this.serverTelemetryManager) {
152
- parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
153
- }
154
- const correlationId = request.correlationId ||
155
- this.config.cryptoInterface.createNewGuid();
156
- parameterBuilder.addCorrelationId(correlationId);
157
- if (this.config.clientCredentials.clientSecret) {
158
- parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
159
- }
160
- // Use clientAssertion from request, fallback to client assertion in base configuration
161
- const clientAssertion = request.clientAssertion ||
162
- this.config.clientCredentials.clientAssertion;
163
- if (clientAssertion) {
164
- parameterBuilder.addClientAssertion(clientAssertion.assertion);
165
- parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
166
- }
167
- if (!msalCommon.StringUtils.isEmptyObj(request.claims) ||
168
- (this.config.authOptions.clientCapabilities &&
169
- this.config.authOptions.clientCapabilities.length > 0)) {
170
- parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
171
- }
172
- return parameterBuilder.createQueryString();
173
- }
7
+ /*
8
+ * Copyright (c) Microsoft Corporation. All rights reserved.
9
+ * Licensed under the MIT License.
10
+ */
11
+ /**
12
+ * OAuth2.0 client credential grant
13
+ */
14
+ class ClientCredentialClient extends msalCommon.BaseClient {
15
+ constructor(configuration, appTokenProvider) {
16
+ super(configuration);
17
+ this.appTokenProvider = appTokenProvider;
18
+ }
19
+ /**
20
+ * Public API to acquire a token with ClientCredential Flow for Confidential clients
21
+ * @param request
22
+ */
23
+ async acquireToken(request) {
24
+ this.scopeSet = new msalCommon.ScopeSet(request.scopes || []);
25
+ if (request.skipCache) {
26
+ return await this.executeTokenRequest(request, this.authority);
27
+ }
28
+ const [cachedAuthenticationResult, lastCacheOutcome] = await this.getCachedAuthenticationResult(request);
29
+ if (cachedAuthenticationResult) {
30
+ // if the token is not expired but must be refreshed; get a new one in the background
31
+ if (lastCacheOutcome === msalCommon.CacheOutcome.PROACTIVELY_REFRESHED) {
32
+ this.logger.info("ClientCredentialClient:getCachedAuthenticationResult - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed.");
33
+ // refresh the access token in the background
34
+ const refreshAccessToken = true;
35
+ await this.executeTokenRequest(request, this.authority, refreshAccessToken);
36
+ }
37
+ // return the cached token
38
+ return cachedAuthenticationResult;
39
+ }
40
+ else {
41
+ return await this.executeTokenRequest(request, this.authority);
42
+ }
43
+ }
44
+ /**
45
+ * looks up cache if the tokens are cached already
46
+ */
47
+ async getCachedAuthenticationResult(request) {
48
+ let lastCacheOutcome = msalCommon.CacheOutcome.NOT_APPLICABLE;
49
+ // read the user-supplied cache into memory, if applicable
50
+ let cacheContext;
51
+ if (this.config.serializableCache && this.config.persistencePlugin) {
52
+ cacheContext = new msalCommon.TokenCacheContext(this.config.serializableCache, false);
53
+ await this.config.persistencePlugin.beforeCacheAccess(cacheContext);
54
+ }
55
+ const cachedAccessToken = this.readAccessTokenFromCache();
56
+ if (this.config.serializableCache &&
57
+ this.config.persistencePlugin &&
58
+ cacheContext) {
59
+ await this.config.persistencePlugin.afterCacheAccess(cacheContext);
60
+ }
61
+ // must refresh due to non-existent access_token
62
+ if (!cachedAccessToken) {
63
+ this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.NO_CACHED_ACCESS_TOKEN);
64
+ return [null, msalCommon.CacheOutcome.NO_CACHED_ACCESS_TOKEN];
65
+ }
66
+ // must refresh due to the expires_in value
67
+ if (msalCommon.TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
68
+ this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
69
+ return [null, msalCommon.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED];
70
+ }
71
+ // must refresh (in the background) due to the refresh_in value
72
+ if (cachedAccessToken.refreshOn &&
73
+ msalCommon.TimeUtils.isTokenExpired(cachedAccessToken.refreshOn.toString(), 0)) {
74
+ lastCacheOutcome = msalCommon.CacheOutcome.PROACTIVELY_REFRESHED;
75
+ this.serverTelemetryManager?.setCacheOutcome(msalCommon.CacheOutcome.PROACTIVELY_REFRESHED);
76
+ }
77
+ return [
78
+ await msalCommon.ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
79
+ account: null,
80
+ idToken: null,
81
+ accessToken: cachedAccessToken,
82
+ refreshToken: null,
83
+ appMetadata: null,
84
+ }, true, request),
85
+ lastCacheOutcome,
86
+ ];
87
+ }
88
+ /**
89
+ * Reads access token from the cache
90
+ */
91
+ readAccessTokenFromCache() {
92
+ const accessTokenFilter = {
93
+ homeAccountId: msalCommon.Constants.EMPTY_STRING,
94
+ environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
95
+ credentialType: msalCommon.CredentialType.ACCESS_TOKEN,
96
+ clientId: this.config.authOptions.clientId,
97
+ realm: this.authority.tenant,
98
+ target: msalCommon.ScopeSet.createSearchScopes(this.scopeSet.asArray()),
99
+ };
100
+ const accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
101
+ if (accessTokens.length < 1) {
102
+ return null;
103
+ }
104
+ else if (accessTokens.length > 1) {
105
+ throw msalCommon.createClientAuthError(msalCommon.ClientAuthErrorCodes.multipleMatchingTokens);
106
+ }
107
+ return accessTokens[0];
108
+ }
109
+ /**
110
+ * Makes a network call to request the token from the service
111
+ * @param request
112
+ * @param authority
113
+ */
114
+ async executeTokenRequest(request, authority, refreshAccessToken) {
115
+ let serverTokenResponse;
116
+ let reqTimestamp;
117
+ if (this.appTokenProvider) {
118
+ this.logger.info("Using appTokenProvider extensibility.");
119
+ const appTokenPropviderParameters = {
120
+ correlationId: request.correlationId,
121
+ tenantId: this.config.authOptions.authority.tenant,
122
+ scopes: request.scopes,
123
+ claims: request.claims,
124
+ };
125
+ reqTimestamp = msalCommon.TimeUtils.nowSeconds();
126
+ const appTokenProviderResult = await this.appTokenProvider(appTokenPropviderParameters);
127
+ serverTokenResponse = {
128
+ access_token: appTokenProviderResult.accessToken,
129
+ expires_in: appTokenProviderResult.expiresInSeconds,
130
+ refresh_in: appTokenProviderResult.refreshInSeconds,
131
+ token_type: msalCommon.AuthenticationScheme.BEARER,
132
+ };
133
+ }
134
+ else {
135
+ const queryParametersString = this.createTokenQueryParameters(request);
136
+ const endpoint = msalCommon.UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
137
+ const requestBody = this.createTokenRequestBody(request);
138
+ const headers = this.createTokenRequestHeaders();
139
+ const thumbprint = {
140
+ clientId: this.config.authOptions.clientId,
141
+ authority: request.authority,
142
+ scopes: request.scopes,
143
+ claims: request.claims,
144
+ authenticationScheme: request.authenticationScheme,
145
+ resourceRequestMethod: request.resourceRequestMethod,
146
+ resourceRequestUri: request.resourceRequestUri,
147
+ shrClaims: request.shrClaims,
148
+ sshKid: request.sshKid,
149
+ };
150
+ reqTimestamp = msalCommon.TimeUtils.nowSeconds();
151
+ const response = await this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
152
+ serverTokenResponse = response.body;
153
+ serverTokenResponse.status = response.status;
154
+ }
155
+ const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
156
+ responseHandler.validateTokenResponse(serverTokenResponse, refreshAccessToken);
157
+ const tokenResponse = await responseHandler.handleServerTokenResponse(serverTokenResponse, this.authority, reqTimestamp, request);
158
+ return tokenResponse;
159
+ }
160
+ /**
161
+ * generate the request to the server in the acceptable format
162
+ * @param request
163
+ */
164
+ createTokenRequestBody(request) {
165
+ const parameterBuilder = new msalCommon.RequestParameterBuilder();
166
+ parameterBuilder.addClientId(this.config.authOptions.clientId);
167
+ parameterBuilder.addScopes(request.scopes, false);
168
+ parameterBuilder.addGrantType(msalCommon.GrantType.CLIENT_CREDENTIALS_GRANT);
169
+ parameterBuilder.addLibraryInfo(this.config.libraryInfo);
170
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
171
+ parameterBuilder.addThrottling();
172
+ if (this.serverTelemetryManager) {
173
+ parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
174
+ }
175
+ const correlationId = request.correlationId ||
176
+ this.config.cryptoInterface.createNewGuid();
177
+ parameterBuilder.addCorrelationId(correlationId);
178
+ if (this.config.clientCredentials.clientSecret) {
179
+ parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
180
+ }
181
+ // Use clientAssertion from request, fallback to client assertion in base configuration
182
+ const clientAssertion = request.clientAssertion ||
183
+ this.config.clientCredentials.clientAssertion;
184
+ if (clientAssertion) {
185
+ parameterBuilder.addClientAssertion(clientAssertion.assertion);
186
+ parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
187
+ }
188
+ if (!msalCommon.StringUtils.isEmptyObj(request.claims) ||
189
+ (this.config.authOptions.clientCapabilities &&
190
+ this.config.authOptions.clientCapabilities.length > 0)) {
191
+ parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
192
+ }
193
+ return parameterBuilder.createQueryString();
194
+ }
174
195
  }
175
196
 
176
197
  exports.ClientCredentialClient = ClientCredentialClient;