@azure/msal-node 2.1.0 → 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/dist/cache/ITokenCache.d.ts +15 -15
- package/dist/cache/NodeStorage.cjs +401 -401
- package/dist/cache/NodeStorage.d.ts +182 -182
- package/dist/cache/NodeStorage.mjs +401 -401
- package/dist/cache/TokenCache.cjs +265 -265
- package/dist/cache/TokenCache.d.ts +90 -90
- package/dist/cache/TokenCache.mjs +265 -265
- package/dist/cache/distributed/DistributedCachePlugin.cjs +26 -26
- package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
- package/dist/cache/distributed/DistributedCachePlugin.mjs +26 -26
- 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 -173
- package/dist/cache/serializer/Deserializer.d.ts +42 -42
- package/dist/cache/serializer/Deserializer.mjs +173 -173
- package/dist/cache/serializer/Serializer.cjs +134 -134
- package/dist/cache/serializer/Serializer.d.ts +39 -39
- package/dist/cache/serializer/Serializer.mjs +134 -134
- 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 -190
- package/dist/client/ClientCredentialClient.cjs.map +1 -1
- package/dist/client/ClientCredentialClient.d.ts +33 -34
- package/dist/client/ClientCredentialClient.d.ts.map +1 -1
- package/dist/client/ClientCredentialClient.mjs +190 -191
- package/dist/client/ClientCredentialClient.mjs.map +1 -1
- package/dist/client/ConfidentialClientApplication.cjs +163 -163
- 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 -164
- 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/IPublicClientApplication.d.ts +42 -42
- package/dist/client/OnBehalfOfClient.cjs +202 -202
- 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 +203 -203
- package/dist/client/OnBehalfOfClient.mjs.map +1 -1
- package/dist/client/PublicClientApplication.cjs +229 -182
- 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 +231 -184
- package/dist/client/PublicClientApplication.mjs.map +1 -1
- package/dist/client/UsernamePasswordClient.cjs +95 -95
- package/dist/client/UsernamePasswordClient.d.ts +25 -25
- package/dist/client/UsernamePasswordClient.mjs +95 -95
- package/dist/config/Configuration.cjs +72 -72
- package/dist/config/Configuration.d.ts +107 -107
- package/dist/config/Configuration.mjs +72 -72
- package/dist/crypto/CryptoProvider.cjs +75 -75
- package/dist/crypto/CryptoProvider.d.ts +52 -52
- package/dist/crypto/CryptoProvider.mjs +75 -75
- package/dist/crypto/GuidGenerator.cjs +22 -22
- package/dist/crypto/GuidGenerator.d.ts +14 -14
- package/dist/crypto/GuidGenerator.mjs +22 -22
- package/dist/crypto/HashUtils.cjs +13 -13
- package/dist/crypto/HashUtils.d.ts +8 -8
- package/dist/crypto/HashUtils.mjs +13 -13
- package/dist/crypto/PkceGenerator.cjs +49 -49
- package/dist/crypto/PkceGenerator.d.ts +22 -22
- package/dist/crypto/PkceGenerator.mjs +49 -49
- package/dist/error/NodeAuthError.cjs +85 -85
- package/dist/error/NodeAuthError.d.ts +65 -65
- package/dist/error/NodeAuthError.mjs +85 -85
- 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.d.ts +6 -6
- package/dist/internals.mjs +8 -8
- package/dist/network/HttpClient.cjs +276 -276
- package/dist/network/HttpClient.d.ts +25 -25
- package/dist/network/HttpClient.mjs +276 -276
- 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 +76 -85
- package/dist/network/LoopbackClient.mjs.map +1 -1
- package/dist/packageMetadata.cjs +3 -3
- package/dist/packageMetadata.d.ts +2 -2
- package/dist/packageMetadata.mjs +3 -3
- 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/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 -80
- package/dist/utils/Constants.d.ts +86 -86
- package/dist/utils/Constants.mjs +80 -80
- package/dist/utils/EncodingUtils.cjs +44 -44
- package/dist/utils/EncodingUtils.d.ts +26 -26
- package/dist/utils/EncodingUtils.mjs +44 -44
- package/dist/utils/NetworkUtils.cjs +38 -38
- package/dist/utils/NetworkUtils.d.ts +5 -5
- package/dist/utils/NetworkUtils.mjs +38 -38
- package/package.json +2 -2
- package/src/client/ClientApplication.ts +3 -2
- package/src/client/ClientAssertion.ts +7 -2
- package/src/client/ClientCredentialClient.ts +32 -34
- package/src/client/ConfidentialClientApplication.ts +11 -4
- package/src/client/DeviceCodeClient.ts +16 -7
- package/src/client/OnBehalfOfClient.ts +11 -4
- package/src/client/PublicClientApplication.ts +69 -13
- package/src/index.ts +4 -0
- package/src/network/LoopbackClient.ts +17 -33
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
/*! @azure/msal-node v2.
|
|
1
|
+
/*! @azure/msal-node v2.2.0-alpha.0 2023-09-20 */
|
|
2
2
|
'use strict';
|
|
3
3
|
import { v4 } from 'uuid';
|
|
4
4
|
|
|
5
|
-
/*
|
|
6
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
-
* Licensed under the MIT License.
|
|
8
|
-
*/
|
|
9
|
-
class GuidGenerator {
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
* RFC4122: The version 4 UUID is meant for generating UUIDs from truly-random or pseudo-random numbers.
|
|
13
|
-
* uuidv4 generates guids from cryprtographically-string random
|
|
14
|
-
*/
|
|
15
|
-
generateGuid() {
|
|
16
|
-
return v4();
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* verifies if a string is GUID
|
|
20
|
-
* @param guid
|
|
21
|
-
*/
|
|
22
|
-
isGuid(guid) {
|
|
23
|
-
const regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
24
|
-
return regexGuid.test(guid);
|
|
25
|
-
}
|
|
5
|
+
/*
|
|
6
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
+
* Licensed under the MIT License.
|
|
8
|
+
*/
|
|
9
|
+
class GuidGenerator {
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* RFC4122: The version 4 UUID is meant for generating UUIDs from truly-random or pseudo-random numbers.
|
|
13
|
+
* uuidv4 generates guids from cryprtographically-string random
|
|
14
|
+
*/
|
|
15
|
+
generateGuid() {
|
|
16
|
+
return v4();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* verifies if a string is GUID
|
|
20
|
+
* @param guid
|
|
21
|
+
*/
|
|
22
|
+
isGuid(guid) {
|
|
23
|
+
const regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
24
|
+
return regexGuid.test(guid);
|
|
25
|
+
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export { GuidGenerator };
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/*! @azure/msal-node v2.
|
|
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 Constants = require('../utils/Constants.cjs');
|
|
6
6
|
var crypto = require('crypto');
|
|
7
7
|
|
|
8
|
-
/*
|
|
9
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
10
|
-
* Licensed under the MIT License.
|
|
11
|
-
*/
|
|
12
|
-
class HashUtils {
|
|
13
|
-
/**
|
|
14
|
-
* generate 'SHA256' hash
|
|
15
|
-
* @param buffer
|
|
16
|
-
*/
|
|
17
|
-
sha256(buffer) {
|
|
18
|
-
return crypto.createHash(Constants.Hash.SHA256).update(buffer).digest();
|
|
19
|
-
}
|
|
8
|
+
/*
|
|
9
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
10
|
+
* Licensed under the MIT License.
|
|
11
|
+
*/
|
|
12
|
+
class HashUtils {
|
|
13
|
+
/**
|
|
14
|
+
* generate 'SHA256' hash
|
|
15
|
+
* @param buffer
|
|
16
|
+
*/
|
|
17
|
+
sha256(buffer) {
|
|
18
|
+
return crypto.createHash(Constants.Hash.SHA256).update(buffer).digest();
|
|
19
|
+
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
exports.HashUtils = HashUtils;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
export declare class HashUtils {
|
|
3
|
-
/**
|
|
4
|
-
* generate 'SHA256' hash
|
|
5
|
-
* @param buffer
|
|
6
|
-
*/
|
|
7
|
-
sha256(buffer: string): Buffer;
|
|
8
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare class HashUtils {
|
|
3
|
+
/**
|
|
4
|
+
* generate 'SHA256' hash
|
|
5
|
+
* @param buffer
|
|
6
|
+
*/
|
|
7
|
+
sha256(buffer: string): Buffer;
|
|
8
|
+
}
|
|
9
9
|
//# sourceMappingURL=HashUtils.d.ts.map
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
/*! @azure/msal-node v2.
|
|
1
|
+
/*! @azure/msal-node v2.2.0-alpha.0 2023-09-20 */
|
|
2
2
|
'use strict';
|
|
3
3
|
import { Hash } from '../utils/Constants.mjs';
|
|
4
4
|
import crypto from 'crypto';
|
|
5
5
|
|
|
6
|
-
/*
|
|
7
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
8
|
-
* Licensed under the MIT License.
|
|
9
|
-
*/
|
|
10
|
-
class HashUtils {
|
|
11
|
-
/**
|
|
12
|
-
* generate 'SHA256' hash
|
|
13
|
-
* @param buffer
|
|
14
|
-
*/
|
|
15
|
-
sha256(buffer) {
|
|
16
|
-
return crypto.createHash(Hash.SHA256).update(buffer).digest();
|
|
17
|
-
}
|
|
6
|
+
/*
|
|
7
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
8
|
+
* Licensed under the MIT License.
|
|
9
|
+
*/
|
|
10
|
+
class HashUtils {
|
|
11
|
+
/**
|
|
12
|
+
* generate 'SHA256' hash
|
|
13
|
+
* @param buffer
|
|
14
|
+
*/
|
|
15
|
+
sha256(buffer) {
|
|
16
|
+
return crypto.createHash(Hash.SHA256).update(buffer).digest();
|
|
17
|
+
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export { HashUtils };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @azure/msal-node v2.
|
|
1
|
+
/*! @azure/msal-node v2.2.0-alpha.0 2023-09-20 */
|
|
2
2
|
'use strict';
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -8,54 +8,54 @@ var EncodingUtils = require('../utils/EncodingUtils.cjs');
|
|
|
8
8
|
var HashUtils = require('./HashUtils.cjs');
|
|
9
9
|
var crypto = require('crypto');
|
|
10
10
|
|
|
11
|
-
/*
|
|
12
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
13
|
-
* Licensed under the MIT License.
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* https://tools.ietf.org/html/rfc7636#page-8
|
|
17
|
-
*/
|
|
18
|
-
class PkceGenerator {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.hashUtils = new HashUtils.HashUtils();
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* generates the codeVerfier and the challenge from the codeVerfier
|
|
24
|
-
* reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
|
|
25
|
-
*/
|
|
26
|
-
async generatePkceCodes() {
|
|
27
|
-
const verifier = this.generateCodeVerifier();
|
|
28
|
-
const challenge = this.generateCodeChallengeFromVerifier(verifier);
|
|
29
|
-
return { verifier, challenge };
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* generates the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.1
|
|
33
|
-
*/
|
|
34
|
-
generateCodeVerifier() {
|
|
35
|
-
const charArr = [];
|
|
36
|
-
const maxNumber = 256 - (256 % Constants.CharSet.CV_CHARSET.length);
|
|
37
|
-
while (charArr.length <= Constants.RANDOM_OCTET_SIZE) {
|
|
38
|
-
const byte = crypto.randomBytes(1)[0];
|
|
39
|
-
if (byte >= maxNumber) {
|
|
40
|
-
/*
|
|
41
|
-
* Ignore this number to maintain randomness.
|
|
42
|
-
* Including it would result in an unequal distribution of characters after doing the modulo
|
|
43
|
-
*/
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
const index = byte % Constants.CharSet.CV_CHARSET.length;
|
|
47
|
-
charArr.push(Constants.CharSet.CV_CHARSET[index]);
|
|
48
|
-
}
|
|
49
|
-
const verifier = charArr.join(msalCommon.Constants.EMPTY_STRING);
|
|
50
|
-
return EncodingUtils.EncodingUtils.base64EncodeUrl(verifier);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* generate the challenge from the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.2
|
|
54
|
-
* @param codeVerifier
|
|
55
|
-
*/
|
|
56
|
-
generateCodeChallengeFromVerifier(codeVerifier) {
|
|
57
|
-
return EncodingUtils.EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(codeVerifier).toString("base64"), "base64");
|
|
58
|
-
}
|
|
11
|
+
/*
|
|
12
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
13
|
+
* Licensed under the MIT License.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* https://tools.ietf.org/html/rfc7636#page-8
|
|
17
|
+
*/
|
|
18
|
+
class PkceGenerator {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.hashUtils = new HashUtils.HashUtils();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* generates the codeVerfier and the challenge from the codeVerfier
|
|
24
|
+
* reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
|
|
25
|
+
*/
|
|
26
|
+
async generatePkceCodes() {
|
|
27
|
+
const verifier = this.generateCodeVerifier();
|
|
28
|
+
const challenge = this.generateCodeChallengeFromVerifier(verifier);
|
|
29
|
+
return { verifier, challenge };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* generates the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.1
|
|
33
|
+
*/
|
|
34
|
+
generateCodeVerifier() {
|
|
35
|
+
const charArr = [];
|
|
36
|
+
const maxNumber = 256 - (256 % Constants.CharSet.CV_CHARSET.length);
|
|
37
|
+
while (charArr.length <= Constants.RANDOM_OCTET_SIZE) {
|
|
38
|
+
const byte = crypto.randomBytes(1)[0];
|
|
39
|
+
if (byte >= maxNumber) {
|
|
40
|
+
/*
|
|
41
|
+
* Ignore this number to maintain randomness.
|
|
42
|
+
* Including it would result in an unequal distribution of characters after doing the modulo
|
|
43
|
+
*/
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const index = byte % Constants.CharSet.CV_CHARSET.length;
|
|
47
|
+
charArr.push(Constants.CharSet.CV_CHARSET[index]);
|
|
48
|
+
}
|
|
49
|
+
const verifier = charArr.join(msalCommon.Constants.EMPTY_STRING);
|
|
50
|
+
return EncodingUtils.EncodingUtils.base64EncodeUrl(verifier);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* generate the challenge from the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.2
|
|
54
|
+
* @param codeVerifier
|
|
55
|
+
*/
|
|
56
|
+
generateCodeChallengeFromVerifier(codeVerifier) {
|
|
57
|
+
return EncodingUtils.EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(codeVerifier).toString("base64"), "base64");
|
|
58
|
+
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
exports.PkceGenerator = PkceGenerator;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { PkceCodes } from "@azure/msal-common";
|
|
2
|
-
/**
|
|
3
|
-
* https://tools.ietf.org/html/rfc7636#page-8
|
|
4
|
-
*/
|
|
5
|
-
export declare class PkceGenerator {
|
|
6
|
-
private hashUtils;
|
|
7
|
-
constructor();
|
|
8
|
-
/**
|
|
9
|
-
* generates the codeVerfier and the challenge from the codeVerfier
|
|
10
|
-
* reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
|
|
11
|
-
*/
|
|
12
|
-
generatePkceCodes(): Promise<PkceCodes>;
|
|
13
|
-
/**
|
|
14
|
-
* generates the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.1
|
|
15
|
-
*/
|
|
16
|
-
private generateCodeVerifier;
|
|
17
|
-
/**
|
|
18
|
-
* generate the challenge from the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.2
|
|
19
|
-
* @param codeVerifier
|
|
20
|
-
*/
|
|
21
|
-
private generateCodeChallengeFromVerifier;
|
|
22
|
-
}
|
|
1
|
+
import { PkceCodes } from "@azure/msal-common";
|
|
2
|
+
/**
|
|
3
|
+
* https://tools.ietf.org/html/rfc7636#page-8
|
|
4
|
+
*/
|
|
5
|
+
export declare class PkceGenerator {
|
|
6
|
+
private hashUtils;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* generates the codeVerfier and the challenge from the codeVerfier
|
|
10
|
+
* reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
|
|
11
|
+
*/
|
|
12
|
+
generatePkceCodes(): Promise<PkceCodes>;
|
|
13
|
+
/**
|
|
14
|
+
* generates the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.1
|
|
15
|
+
*/
|
|
16
|
+
private generateCodeVerifier;
|
|
17
|
+
/**
|
|
18
|
+
* generate the challenge from the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.2
|
|
19
|
+
* @param codeVerifier
|
|
20
|
+
*/
|
|
21
|
+
private generateCodeChallengeFromVerifier;
|
|
22
|
+
}
|
|
23
23
|
//# sourceMappingURL=PkceGenerator.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @azure/msal-node v2.
|
|
1
|
+
/*! @azure/msal-node v2.2.0-alpha.0 2023-09-20 */
|
|
2
2
|
'use strict';
|
|
3
3
|
import { Constants } from '@azure/msal-common';
|
|
4
4
|
import { RANDOM_OCTET_SIZE, CharSet } from '../utils/Constants.mjs';
|
|
@@ -6,54 +6,54 @@ import { EncodingUtils } from '../utils/EncodingUtils.mjs';
|
|
|
6
6
|
import { HashUtils } from './HashUtils.mjs';
|
|
7
7
|
import crypto from 'crypto';
|
|
8
8
|
|
|
9
|
-
/*
|
|
10
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
11
|
-
* Licensed under the MIT License.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* https://tools.ietf.org/html/rfc7636#page-8
|
|
15
|
-
*/
|
|
16
|
-
class PkceGenerator {
|
|
17
|
-
constructor() {
|
|
18
|
-
this.hashUtils = new HashUtils();
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* generates the codeVerfier and the challenge from the codeVerfier
|
|
22
|
-
* reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
|
|
23
|
-
*/
|
|
24
|
-
async generatePkceCodes() {
|
|
25
|
-
const verifier = this.generateCodeVerifier();
|
|
26
|
-
const challenge = this.generateCodeChallengeFromVerifier(verifier);
|
|
27
|
-
return { verifier, challenge };
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* generates the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.1
|
|
31
|
-
*/
|
|
32
|
-
generateCodeVerifier() {
|
|
33
|
-
const charArr = [];
|
|
34
|
-
const maxNumber = 256 - (256 % CharSet.CV_CHARSET.length);
|
|
35
|
-
while (charArr.length <= RANDOM_OCTET_SIZE) {
|
|
36
|
-
const byte = crypto.randomBytes(1)[0];
|
|
37
|
-
if (byte >= maxNumber) {
|
|
38
|
-
/*
|
|
39
|
-
* Ignore this number to maintain randomness.
|
|
40
|
-
* Including it would result in an unequal distribution of characters after doing the modulo
|
|
41
|
-
*/
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
const index = byte % CharSet.CV_CHARSET.length;
|
|
45
|
-
charArr.push(CharSet.CV_CHARSET[index]);
|
|
46
|
-
}
|
|
47
|
-
const verifier = charArr.join(Constants.EMPTY_STRING);
|
|
48
|
-
return EncodingUtils.base64EncodeUrl(verifier);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* generate the challenge from the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.2
|
|
52
|
-
* @param codeVerifier
|
|
53
|
-
*/
|
|
54
|
-
generateCodeChallengeFromVerifier(codeVerifier) {
|
|
55
|
-
return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(codeVerifier).toString("base64"), "base64");
|
|
56
|
-
}
|
|
9
|
+
/*
|
|
10
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
11
|
+
* Licensed under the MIT License.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* https://tools.ietf.org/html/rfc7636#page-8
|
|
15
|
+
*/
|
|
16
|
+
class PkceGenerator {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.hashUtils = new HashUtils();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* generates the codeVerfier and the challenge from the codeVerfier
|
|
22
|
+
* reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
|
|
23
|
+
*/
|
|
24
|
+
async generatePkceCodes() {
|
|
25
|
+
const verifier = this.generateCodeVerifier();
|
|
26
|
+
const challenge = this.generateCodeChallengeFromVerifier(verifier);
|
|
27
|
+
return { verifier, challenge };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* generates the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.1
|
|
31
|
+
*/
|
|
32
|
+
generateCodeVerifier() {
|
|
33
|
+
const charArr = [];
|
|
34
|
+
const maxNumber = 256 - (256 % CharSet.CV_CHARSET.length);
|
|
35
|
+
while (charArr.length <= RANDOM_OCTET_SIZE) {
|
|
36
|
+
const byte = crypto.randomBytes(1)[0];
|
|
37
|
+
if (byte >= maxNumber) {
|
|
38
|
+
/*
|
|
39
|
+
* Ignore this number to maintain randomness.
|
|
40
|
+
* Including it would result in an unequal distribution of characters after doing the modulo
|
|
41
|
+
*/
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const index = byte % CharSet.CV_CHARSET.length;
|
|
45
|
+
charArr.push(CharSet.CV_CHARSET[index]);
|
|
46
|
+
}
|
|
47
|
+
const verifier = charArr.join(Constants.EMPTY_STRING);
|
|
48
|
+
return EncodingUtils.base64EncodeUrl(verifier);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* generate the challenge from the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.2
|
|
52
|
+
* @param codeVerifier
|
|
53
|
+
*/
|
|
54
|
+
generateCodeChallengeFromVerifier(codeVerifier) {
|
|
55
|
+
return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(codeVerifier).toString("base64"), "base64");
|
|
56
|
+
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
export { PkceGenerator };
|
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
/*! @azure/msal-node v2.
|
|
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
|
-
* NodeAuthErrorMessage class containing string constants used by error codes and messages.
|
|
13
|
-
*/
|
|
14
|
-
const NodeAuthErrorMessage = {
|
|
15
|
-
invalidLoopbackAddressType: {
|
|
16
|
-
code: "invalid_loopback_server_address_type",
|
|
17
|
-
desc: "Loopback server address is not type string. This is unexpected.",
|
|
18
|
-
},
|
|
19
|
-
unableToLoadRedirectUri: {
|
|
20
|
-
code: "unable_to_load_redirectUrl",
|
|
21
|
-
desc: "Loopback server callback was invoked without a url. This is unexpected.",
|
|
22
|
-
},
|
|
23
|
-
noAuthCodeInResponse: {
|
|
24
|
-
code: "no_auth_code_in_response",
|
|
25
|
-
desc: "No auth code found in the server response. Please check your network trace to determine what happened.",
|
|
26
|
-
},
|
|
27
|
-
noLoopbackServerExists: {
|
|
28
|
-
code: "no_loopback_server_exists",
|
|
29
|
-
desc: "No loopback server exists yet.",
|
|
30
|
-
},
|
|
31
|
-
loopbackServerAlreadyExists: {
|
|
32
|
-
code: "loopback_server_already_exists",
|
|
33
|
-
desc: "Loopback server already exists. Cannot create another.",
|
|
34
|
-
},
|
|
35
|
-
loopbackServerTimeout: {
|
|
36
|
-
code: "loopback_server_timeout",
|
|
37
|
-
desc: "Timed out waiting for auth code listener to be registered.",
|
|
38
|
-
},
|
|
39
|
-
stateNotFoundError: {
|
|
40
|
-
code: "state_not_found",
|
|
41
|
-
desc: "State not found. Please verify that the request originated from msal.",
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
class NodeAuthError extends msalCommon.AuthError {
|
|
45
|
-
constructor(errorCode, errorMessage) {
|
|
46
|
-
super(errorCode, errorMessage);
|
|
47
|
-
this.name = "NodeAuthError";
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Creates an error thrown if loopback server address is of type string.
|
|
51
|
-
*/
|
|
52
|
-
static createInvalidLoopbackAddressTypeError() {
|
|
53
|
-
return new NodeAuthError(NodeAuthErrorMessage.invalidLoopbackAddressType.code, `${NodeAuthErrorMessage.invalidLoopbackAddressType.desc}`);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Creates an error thrown if the loopback server is unable to get a url.
|
|
57
|
-
*/
|
|
58
|
-
static createUnableToLoadRedirectUrlError() {
|
|
59
|
-
return new NodeAuthError(NodeAuthErrorMessage.unableToLoadRedirectUri.code, `${NodeAuthErrorMessage.unableToLoadRedirectUri.desc}`);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Creates an error thrown if the server response does not contain an auth code.
|
|
63
|
-
*/
|
|
64
|
-
static createNoAuthCodeInResponseError() {
|
|
65
|
-
return new NodeAuthError(NodeAuthErrorMessage.noAuthCodeInResponse.code, `${NodeAuthErrorMessage.noAuthCodeInResponse.desc}`);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Creates an error thrown if the loopback server has not been spun up yet.
|
|
69
|
-
*/
|
|
70
|
-
static createNoLoopbackServerExistsError() {
|
|
71
|
-
return new NodeAuthError(NodeAuthErrorMessage.noLoopbackServerExists.code, `${NodeAuthErrorMessage.noLoopbackServerExists.desc}`);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Creates an error thrown if a loopback server already exists when attempting to create another one.
|
|
75
|
-
*/
|
|
76
|
-
static createLoopbackServerAlreadyExistsError() {
|
|
77
|
-
return new NodeAuthError(NodeAuthErrorMessage.loopbackServerAlreadyExists.code, `${NodeAuthErrorMessage.loopbackServerAlreadyExists.desc}`);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Creates an error thrown if the loopback server times out registering the auth code listener.
|
|
81
|
-
*/
|
|
82
|
-
static createLoopbackServerTimeoutError() {
|
|
83
|
-
return new NodeAuthError(NodeAuthErrorMessage.loopbackServerTimeout.code, `${NodeAuthErrorMessage.loopbackServerTimeout.desc}`);
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Creates an error thrown when the state is not present.
|
|
87
|
-
*/
|
|
88
|
-
static createStateNotFoundError() {
|
|
89
|
-
return new NodeAuthError(NodeAuthErrorMessage.stateNotFoundError.code, NodeAuthErrorMessage.stateNotFoundError.desc);
|
|
90
|
-
}
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
9
|
+
* Licensed under the MIT License.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* NodeAuthErrorMessage class containing string constants used by error codes and messages.
|
|
13
|
+
*/
|
|
14
|
+
const NodeAuthErrorMessage = {
|
|
15
|
+
invalidLoopbackAddressType: {
|
|
16
|
+
code: "invalid_loopback_server_address_type",
|
|
17
|
+
desc: "Loopback server address is not type string. This is unexpected.",
|
|
18
|
+
},
|
|
19
|
+
unableToLoadRedirectUri: {
|
|
20
|
+
code: "unable_to_load_redirectUrl",
|
|
21
|
+
desc: "Loopback server callback was invoked without a url. This is unexpected.",
|
|
22
|
+
},
|
|
23
|
+
noAuthCodeInResponse: {
|
|
24
|
+
code: "no_auth_code_in_response",
|
|
25
|
+
desc: "No auth code found in the server response. Please check your network trace to determine what happened.",
|
|
26
|
+
},
|
|
27
|
+
noLoopbackServerExists: {
|
|
28
|
+
code: "no_loopback_server_exists",
|
|
29
|
+
desc: "No loopback server exists yet.",
|
|
30
|
+
},
|
|
31
|
+
loopbackServerAlreadyExists: {
|
|
32
|
+
code: "loopback_server_already_exists",
|
|
33
|
+
desc: "Loopback server already exists. Cannot create another.",
|
|
34
|
+
},
|
|
35
|
+
loopbackServerTimeout: {
|
|
36
|
+
code: "loopback_server_timeout",
|
|
37
|
+
desc: "Timed out waiting for auth code listener to be registered.",
|
|
38
|
+
},
|
|
39
|
+
stateNotFoundError: {
|
|
40
|
+
code: "state_not_found",
|
|
41
|
+
desc: "State not found. Please verify that the request originated from msal.",
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
class NodeAuthError extends msalCommon.AuthError {
|
|
45
|
+
constructor(errorCode, errorMessage) {
|
|
46
|
+
super(errorCode, errorMessage);
|
|
47
|
+
this.name = "NodeAuthError";
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates an error thrown if loopback server address is of type string.
|
|
51
|
+
*/
|
|
52
|
+
static createInvalidLoopbackAddressTypeError() {
|
|
53
|
+
return new NodeAuthError(NodeAuthErrorMessage.invalidLoopbackAddressType.code, `${NodeAuthErrorMessage.invalidLoopbackAddressType.desc}`);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates an error thrown if the loopback server is unable to get a url.
|
|
57
|
+
*/
|
|
58
|
+
static createUnableToLoadRedirectUrlError() {
|
|
59
|
+
return new NodeAuthError(NodeAuthErrorMessage.unableToLoadRedirectUri.code, `${NodeAuthErrorMessage.unableToLoadRedirectUri.desc}`);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates an error thrown if the server response does not contain an auth code.
|
|
63
|
+
*/
|
|
64
|
+
static createNoAuthCodeInResponseError() {
|
|
65
|
+
return new NodeAuthError(NodeAuthErrorMessage.noAuthCodeInResponse.code, `${NodeAuthErrorMessage.noAuthCodeInResponse.desc}`);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates an error thrown if the loopback server has not been spun up yet.
|
|
69
|
+
*/
|
|
70
|
+
static createNoLoopbackServerExistsError() {
|
|
71
|
+
return new NodeAuthError(NodeAuthErrorMessage.noLoopbackServerExists.code, `${NodeAuthErrorMessage.noLoopbackServerExists.desc}`);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates an error thrown if a loopback server already exists when attempting to create another one.
|
|
75
|
+
*/
|
|
76
|
+
static createLoopbackServerAlreadyExistsError() {
|
|
77
|
+
return new NodeAuthError(NodeAuthErrorMessage.loopbackServerAlreadyExists.code, `${NodeAuthErrorMessage.loopbackServerAlreadyExists.desc}`);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Creates an error thrown if the loopback server times out registering the auth code listener.
|
|
81
|
+
*/
|
|
82
|
+
static createLoopbackServerTimeoutError() {
|
|
83
|
+
return new NodeAuthError(NodeAuthErrorMessage.loopbackServerTimeout.code, `${NodeAuthErrorMessage.loopbackServerTimeout.desc}`);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Creates an error thrown when the state is not present.
|
|
87
|
+
*/
|
|
88
|
+
static createStateNotFoundError() {
|
|
89
|
+
return new NodeAuthError(NodeAuthErrorMessage.stateNotFoundError.code, NodeAuthErrorMessage.stateNotFoundError.desc);
|
|
90
|
+
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
exports.NodeAuthError = NodeAuthError;
|