@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.
- package/README.md +3 -1
- package/dist/cache/ITokenCache.d.ts +15 -15
- package/dist/cache/NodeStorage.cjs +401 -401
- package/dist/cache/NodeStorage.cjs.map +1 -1
- package/dist/cache/NodeStorage.d.ts +182 -182
- package/dist/cache/NodeStorage.d.ts.map +1 -1
- package/dist/cache/NodeStorage.mjs +401 -401
- package/dist/cache/NodeStorage.mjs.map +1 -1
- package/dist/cache/TokenCache.cjs +265 -269
- package/dist/cache/TokenCache.cjs.map +1 -1
- package/dist/cache/TokenCache.d.ts +90 -90
- package/dist/cache/TokenCache.d.ts.map +1 -1
- package/dist/cache/TokenCache.mjs +266 -270
- package/dist/cache/TokenCache.mjs.map +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.cjs +26 -26
- package/dist/cache/distributed/DistributedCachePlugin.cjs.map +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
- package/dist/cache/distributed/DistributedCachePlugin.d.ts.map +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.mjs +26 -26
- package/dist/cache/distributed/DistributedCachePlugin.mjs.map +1 -1
- package/dist/cache/distributed/ICacheClient.d.ts +17 -17
- package/dist/cache/distributed/IPartitionManager.d.ts +28 -28
- package/dist/cache/serializer/Deserializer.cjs +173 -175
- package/dist/cache/serializer/Deserializer.cjs.map +1 -1
- package/dist/cache/serializer/Deserializer.d.ts +42 -42
- package/dist/cache/serializer/Deserializer.d.ts.map +1 -1
- package/dist/cache/serializer/Deserializer.mjs +174 -176
- package/dist/cache/serializer/Deserializer.mjs.map +1 -1
- package/dist/cache/serializer/Serializer.cjs +134 -134
- package/dist/cache/serializer/Serializer.cjs.map +1 -1
- package/dist/cache/serializer/Serializer.d.ts +39 -39
- package/dist/cache/serializer/Serializer.d.ts.map +1 -1
- package/dist/cache/serializer/Serializer.mjs +134 -134
- package/dist/cache/serializer/Serializer.mjs.map +1 -1
- package/dist/cache/serializer/SerializerTypes.d.ts +101 -101
- package/dist/client/ClientApplication.cjs +333 -333
- package/dist/client/ClientApplication.cjs.map +1 -1
- package/dist/client/ClientApplication.d.ts +142 -142
- package/dist/client/ClientApplication.d.ts.map +1 -1
- package/dist/client/ClientApplication.mjs +334 -334
- package/dist/client/ClientApplication.mjs.map +1 -1
- package/dist/client/ClientAssertion.cjs +116 -116
- package/dist/client/ClientAssertion.cjs.map +1 -1
- package/dist/client/ClientAssertion.d.ts +46 -46
- package/dist/client/ClientAssertion.d.ts.map +1 -1
- package/dist/client/ClientAssertion.mjs +117 -117
- package/dist/client/ClientAssertion.mjs.map +1 -1
- package/dist/client/ClientCredentialClient.cjs +189 -168
- package/dist/client/ClientCredentialClient.cjs.map +1 -1
- package/dist/client/ClientCredentialClient.d.ts +33 -33
- package/dist/client/ClientCredentialClient.d.ts.map +1 -1
- package/dist/client/ClientCredentialClient.mjs +190 -169
- package/dist/client/ClientCredentialClient.mjs.map +1 -1
- package/dist/client/ConfidentialClientApplication.cjs +163 -164
- package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
- package/dist/client/ConfidentialClientApplication.d.ts +58 -58
- package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
- package/dist/client/ConfidentialClientApplication.mjs +164 -165
- package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
- package/dist/client/DeviceCodeClient.cjs +207 -207
- package/dist/client/DeviceCodeClient.cjs.map +1 -1
- package/dist/client/DeviceCodeClient.d.ts +53 -53
- package/dist/client/DeviceCodeClient.d.ts.map +1 -1
- package/dist/client/DeviceCodeClient.mjs +208 -208
- package/dist/client/DeviceCodeClient.mjs.map +1 -1
- package/dist/client/IConfidentialClientApplication.d.ts +39 -39
- package/dist/client/IConfidentialClientApplication.d.ts.map +1 -1
- package/dist/client/IPublicClientApplication.d.ts +42 -42
- package/dist/client/IPublicClientApplication.d.ts.map +1 -1
- package/dist/client/OnBehalfOfClient.cjs +203 -204
- package/dist/client/OnBehalfOfClient.cjs.map +1 -1
- package/dist/client/OnBehalfOfClient.d.ts +47 -47
- package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
- package/dist/client/OnBehalfOfClient.mjs +204 -205
- package/dist/client/OnBehalfOfClient.mjs.map +1 -1
- package/dist/client/PublicClientApplication.cjs +229 -175
- package/dist/client/PublicClientApplication.cjs.map +1 -1
- package/dist/client/PublicClientApplication.d.ts +71 -65
- package/dist/client/PublicClientApplication.d.ts.map +1 -1
- package/dist/client/PublicClientApplication.mjs +232 -178
- package/dist/client/PublicClientApplication.mjs.map +1 -1
- package/dist/client/UsernamePasswordClient.cjs +95 -95
- package/dist/client/UsernamePasswordClient.cjs.map +1 -1
- package/dist/client/UsernamePasswordClient.d.ts +25 -25
- package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
- package/dist/client/UsernamePasswordClient.mjs +95 -95
- package/dist/client/UsernamePasswordClient.mjs.map +1 -1
- package/dist/config/Configuration.cjs +72 -72
- package/dist/config/Configuration.cjs.map +1 -1
- package/dist/config/Configuration.d.ts +107 -107
- package/dist/config/Configuration.mjs +72 -72
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/crypto/CryptoProvider.cjs +75 -75
- package/dist/crypto/CryptoProvider.cjs.map +1 -1
- package/dist/crypto/CryptoProvider.d.ts +52 -52
- package/dist/crypto/CryptoProvider.mjs +75 -75
- package/dist/crypto/CryptoProvider.mjs.map +1 -1
- package/dist/crypto/GuidGenerator.cjs +22 -22
- package/dist/crypto/GuidGenerator.cjs.map +1 -1
- package/dist/crypto/GuidGenerator.d.ts +14 -14
- package/dist/crypto/GuidGenerator.mjs +22 -22
- package/dist/crypto/GuidGenerator.mjs.map +1 -1
- package/dist/crypto/HashUtils.cjs +13 -13
- package/dist/crypto/HashUtils.cjs.map +1 -1
- package/dist/crypto/HashUtils.d.ts +8 -8
- package/dist/crypto/HashUtils.mjs +13 -13
- package/dist/crypto/HashUtils.mjs.map +1 -1
- package/dist/crypto/PkceGenerator.cjs +49 -49
- package/dist/crypto/PkceGenerator.cjs.map +1 -1
- package/dist/crypto/PkceGenerator.d.ts +22 -22
- package/dist/crypto/PkceGenerator.mjs +49 -49
- package/dist/crypto/PkceGenerator.mjs.map +1 -1
- package/dist/error/NodeAuthError.cjs +85 -85
- package/dist/error/NodeAuthError.cjs.map +1 -1
- package/dist/error/NodeAuthError.d.ts +65 -65
- package/dist/error/NodeAuthError.mjs +85 -85
- package/dist/error/NodeAuthError.mjs.map +1 -1
- package/dist/index.cjs +17 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +42 -42
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/internals.cjs +8 -8
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.d.ts +6 -6
- package/dist/internals.d.ts.map +1 -1
- package/dist/internals.mjs +8 -8
- package/dist/internals.mjs.map +1 -1
- package/dist/network/HttpClient.cjs +277 -276
- package/dist/network/HttpClient.cjs.map +1 -1
- package/dist/network/HttpClient.d.ts +25 -25
- package/dist/network/HttpClient.d.ts.map +1 -1
- package/dist/network/HttpClient.mjs +278 -277
- package/dist/network/HttpClient.mjs.map +1 -1
- package/dist/network/ILoopbackClient.d.ts +10 -10
- package/dist/network/LoopbackClient.cjs +75 -84
- package/dist/network/LoopbackClient.cjs.map +1 -1
- package/dist/network/LoopbackClient.d.ts +21 -21
- package/dist/network/LoopbackClient.d.ts.map +1 -1
- package/dist/network/LoopbackClient.mjs +77 -86
- package/dist/network/LoopbackClient.mjs.map +1 -1
- package/dist/packageMetadata.cjs +4 -4
- package/dist/packageMetadata.cjs.map +1 -1
- package/dist/packageMetadata.d.ts +2 -2
- package/dist/packageMetadata.mjs +4 -4
- package/dist/packageMetadata.mjs.map +1 -1
- package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
- package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
- package/dist/request/ClientCredentialRequest.d.ts +14 -14
- package/dist/request/DeviceCodeRequest.d.ts +15 -15
- package/dist/request/InteractiveRequest.d.ts +22 -22
- package/dist/request/InteractiveRequest.d.ts.map +1 -1
- package/dist/request/OnBehalfOfRequest.d.ts +14 -14
- package/dist/request/RefreshTokenRequest.d.ts +17 -17
- package/dist/request/SignOutRequest.d.ts +5 -5
- package/dist/request/SilentFlowRequest.d.ts +16 -16
- package/dist/request/UsernamePasswordRequest.d.ts +19 -19
- package/dist/utils/Constants.cjs +80 -90
- package/dist/utils/Constants.cjs.map +1 -1
- package/dist/utils/Constants.d.ts +86 -96
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +81 -90
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/EncodingUtils.cjs +44 -44
- package/dist/utils/EncodingUtils.cjs.map +1 -1
- package/dist/utils/EncodingUtils.d.ts +26 -26
- package/dist/utils/EncodingUtils.mjs +44 -44
- package/dist/utils/EncodingUtils.mjs.map +1 -1
- package/dist/utils/NetworkUtils.cjs +38 -38
- package/dist/utils/NetworkUtils.cjs.map +1 -1
- package/dist/utils/NetworkUtils.d.ts +5 -5
- package/dist/utils/NetworkUtils.mjs +38 -38
- package/dist/utils/NetworkUtils.mjs.map +1 -1
- package/package.json +8 -5
- package/src/cache/ITokenCache.ts +24 -0
- package/src/cache/NodeStorage.ts +533 -0
- package/src/cache/TokenCache.ts +358 -0
- package/src/cache/distributed/DistributedCachePlugin.ts +56 -0
- package/src/cache/distributed/ICacheClient.ts +23 -0
- package/src/cache/distributed/IPartitionManager.ts +35 -0
- package/src/cache/serializer/Deserializer.ts +218 -0
- package/src/cache/serializer/Serializer.ts +173 -0
- package/src/cache/serializer/SerializerTypes.ts +121 -0
- package/src/client/ClientApplication.ts +596 -0
- package/src/client/ClientAssertion.ts +165 -0
- package/src/client/ClientCredentialClient.ts +346 -0
- package/src/client/ConfidentialClientApplication.ts +268 -0
- package/src/client/DeviceCodeClient.ts +369 -0
- package/src/client/IConfidentialClientApplication.ts +72 -0
- package/src/client/IPublicClientApplication.ts +72 -0
- package/src/client/OnBehalfOfClient.ts +368 -0
- package/src/client/PublicClientApplication.ts +339 -0
- package/src/client/UsernamePasswordClient.ts +180 -0
- package/src/config/Configuration.ts +201 -0
- package/src/crypto/CryptoProvider.ts +98 -0
- package/src/crypto/GuidGenerator.ts +28 -0
- package/src/crypto/HashUtils.ts +17 -0
- package/src/crypto/PkceGenerator.ts +63 -0
- package/src/error/NodeAuthError.ts +117 -0
- package/src/index.ts +125 -0
- package/src/internals.ts +12 -0
- package/src/network/HttpClient.ts +425 -0
- package/src/network/ILoopbackClient.ts +19 -0
- package/src/network/LoopbackClient.ts +110 -0
- package/src/packageMetadata.ts +3 -0
- package/src/request/AuthorizationCodeRequest.ts +39 -0
- package/src/request/AuthorizationUrlRequest.ts +50 -0
- package/src/request/ClientCredentialRequest.ts +29 -0
- package/src/request/DeviceCodeRequest.ts +34 -0
- package/src/request/InteractiveRequest.ts +39 -0
- package/src/request/OnBehalfOfRequest.ts +30 -0
- package/src/request/RefreshTokenRequest.ts +34 -0
- package/src/request/SignOutRequest.ts +11 -0
- package/src/request/SilentFlowRequest.ts +32 -0
- package/src/request/UsernamePasswordRequest.ts +36 -0
- package/src/utils/Constants.ts +103 -0
- package/src/utils/EncodingUtils.ts +50 -0
- package/src/utils/NetworkUtils.ts +49 -0
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
/*! @azure/msal-node v2.0.
|
|
1
|
+
/*! @azure/msal-node v2.2.0-alpha.0 2023-09-20 */
|
|
2
2
|
'use strict';
|
|
3
3
|
import jwt from 'jsonwebtoken';
|
|
4
|
-
import {
|
|
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
|
|
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":";;;;;;;
|
|
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.
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
this.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
this.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
scopes: request.scopes,
|
|
123
|
-
claims: request.claims,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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;
|