@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,193 +1,240 @@
|
|
|
1
|
-
/*! @azure/msal-node v2.
|
|
1
|
+
/*! @azure/msal-node v2.2.0-alpha.0 2023-09-20 */
|
|
2
2
|
'use strict';
|
|
3
|
-
import { ApiId, Constants as Constants$1 } from '../utils/Constants.mjs';
|
|
3
|
+
import { ApiId, LOOPBACK_SERVER_CONSTANTS, Constants as Constants$1 } from '../utils/Constants.mjs';
|
|
4
4
|
import { AuthError, OIDC_DEFAULT_SCOPES, ResponseMode, CodeChallengeMethodValues, ServerError, Constants } from '@azure/msal-common';
|
|
5
5
|
import { ClientApplication } from './ClientApplication.mjs';
|
|
6
|
-
import { NodeAuthError } from '../error/NodeAuthError.mjs';
|
|
6
|
+
import { NodeAuthError, NodeAuthErrorMessage } from '../error/NodeAuthError.mjs';
|
|
7
7
|
import { LoopbackClient } from '../network/LoopbackClient.mjs';
|
|
8
8
|
import { DeviceCodeClient } from './DeviceCodeClient.mjs';
|
|
9
9
|
|
|
10
|
-
/*
|
|
11
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
12
|
-
* Licensed under the MIT License.
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* This class is to be used to acquire tokens for public client applications (desktop, mobile). Public client applications
|
|
16
|
-
* are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
class PublicClientApplication extends ClientApplication {
|
|
20
|
-
/**
|
|
21
|
-
* Important attributes in the Configuration object for auth are:
|
|
22
|
-
* - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal.
|
|
23
|
-
* - authority: the authority URL for your application.
|
|
24
|
-
*
|
|
25
|
-
* AAD authorities are of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
|
|
26
|
-
* - If your application supports Accounts in one organizational directory, replace "Enter_the_Tenant_Info_Here" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).
|
|
27
|
-
* - If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
|
|
28
|
-
* - If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
|
|
29
|
-
* - To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
|
|
30
|
-
*
|
|
31
|
-
* Azure B2C authorities are of the form https://\{instance\}/\{tenant\}/\{policy\}. Each policy is considered
|
|
32
|
-
* its own authority. You will have to set the all of the knownAuthorities at the time of the client application
|
|
33
|
-
* construction.
|
|
34
|
-
*
|
|
35
|
-
* ADFS authorities are of the form https://\{instance\}/adfs.
|
|
36
|
-
*/
|
|
37
|
-
constructor(configuration) {
|
|
38
|
-
super(configuration);
|
|
39
|
-
if (this.config.broker.nativeBrokerPlugin) {
|
|
40
|
-
if (this.config.broker.nativeBrokerPlugin.isBrokerAvailable) {
|
|
41
|
-
this.nativeBrokerPlugin = this.config.broker.nativeBrokerPlugin;
|
|
42
|
-
this.nativeBrokerPlugin.setLogger(this.config.system.loggerOptions);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
this.logger.warning("NativeBroker implementation was provided but the broker is unavailable.");
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Acquires a token from the authority using OAuth2.0 device code flow.
|
|
51
|
-
* This flow is designed for devices that do not have access to a browser or have input constraints.
|
|
52
|
-
* The authorization server issues a DeviceCode object with a verification code, an end-user code,
|
|
53
|
-
* and the end-user verification URI. The DeviceCode object is provided through a callback, and the end-user should be
|
|
54
|
-
* instructed to use another device to navigate to the verification URI to input credentials.
|
|
55
|
-
* Since the client cannot receive incoming requests, it polls the authorization server repeatedly
|
|
56
|
-
* until the end-user completes input of credentials.
|
|
57
|
-
*/
|
|
58
|
-
async acquireTokenByDeviceCode(request) {
|
|
59
|
-
this.logger.info("acquireTokenByDeviceCode called", request.correlationId);
|
|
60
|
-
const validRequest = Object.assign(request, await this.initializeBaseRequest(request));
|
|
61
|
-
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
|
|
62
|
-
try {
|
|
63
|
-
const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
64
|
-
const deviceCodeClient = new DeviceCodeClient(deviceCodeConfig);
|
|
65
|
-
this.logger.verbose("Device code client created", validRequest.correlationId);
|
|
66
|
-
return deviceCodeClient.acquireToken(validRequest);
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
if (e instanceof AuthError) {
|
|
70
|
-
e.setCorrelationId(validRequest.correlationId);
|
|
71
|
-
}
|
|
72
|
-
serverTelemetryManager.cacheFailedRequest(e);
|
|
73
|
-
throw e;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
|
|
78
|
-
*/
|
|
79
|
-
async acquireTokenInteractive(request) {
|
|
80
|
-
const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
|
|
81
|
-
this.logger.trace("acquireTokenInteractive called", correlationId);
|
|
82
|
-
const { openBrowser, successTemplate, errorTemplate, windowHandle, loopbackClient: customLoopbackClient, ...remainingProperties } = request;
|
|
83
|
-
if (this.nativeBrokerPlugin) {
|
|
84
|
-
const brokerRequest = {
|
|
85
|
-
...remainingProperties,
|
|
86
|
-
clientId: this.config.auth.clientId,
|
|
87
|
-
scopes: request.scopes || OIDC_DEFAULT_SCOPES,
|
|
88
|
-
redirectUri: `${Constants$1.HTTP_PROTOCOL}${Constants$1.LOCALHOST}`,
|
|
89
|
-
authority: request.authority || this.config.auth.authority,
|
|
90
|
-
correlationId: correlationId,
|
|
91
|
-
extraParameters: {
|
|
92
|
-
...remainingProperties.extraQueryParameters,
|
|
93
|
-
...remainingProperties.tokenQueryParameters,
|
|
94
|
-
},
|
|
95
|
-
accountId: remainingProperties.account?.nativeAccountId,
|
|
96
|
-
};
|
|
97
|
-
return this.nativeBrokerPlugin.acquireTokenInteractive(brokerRequest, windowHandle);
|
|
98
|
-
}
|
|
99
|
-
const { verifier, challenge } = await this.cryptoProvider.generatePkceCodes();
|
|
100
|
-
const loopbackClient = customLoopbackClient || new LoopbackClient();
|
|
101
|
-
let
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
10
|
+
/*
|
|
11
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
12
|
+
* Licensed under the MIT License.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* This class is to be used to acquire tokens for public client applications (desktop, mobile). Public client applications
|
|
16
|
+
* are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
class PublicClientApplication extends ClientApplication {
|
|
20
|
+
/**
|
|
21
|
+
* Important attributes in the Configuration object for auth are:
|
|
22
|
+
* - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal.
|
|
23
|
+
* - authority: the authority URL for your application.
|
|
24
|
+
*
|
|
25
|
+
* AAD authorities are of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
|
|
26
|
+
* - If your application supports Accounts in one organizational directory, replace "Enter_the_Tenant_Info_Here" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).
|
|
27
|
+
* - If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
|
|
28
|
+
* - If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
|
|
29
|
+
* - To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
|
|
30
|
+
*
|
|
31
|
+
* Azure B2C authorities are of the form https://\{instance\}/\{tenant\}/\{policy\}. Each policy is considered
|
|
32
|
+
* its own authority. You will have to set the all of the knownAuthorities at the time of the client application
|
|
33
|
+
* construction.
|
|
34
|
+
*
|
|
35
|
+
* ADFS authorities are of the form https://\{instance\}/adfs.
|
|
36
|
+
*/
|
|
37
|
+
constructor(configuration) {
|
|
38
|
+
super(configuration);
|
|
39
|
+
if (this.config.broker.nativeBrokerPlugin) {
|
|
40
|
+
if (this.config.broker.nativeBrokerPlugin.isBrokerAvailable) {
|
|
41
|
+
this.nativeBrokerPlugin = this.config.broker.nativeBrokerPlugin;
|
|
42
|
+
this.nativeBrokerPlugin.setLogger(this.config.system.loggerOptions);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.logger.warning("NativeBroker implementation was provided but the broker is unavailable.");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Acquires a token from the authority using OAuth2.0 device code flow.
|
|
51
|
+
* This flow is designed for devices that do not have access to a browser or have input constraints.
|
|
52
|
+
* The authorization server issues a DeviceCode object with a verification code, an end-user code,
|
|
53
|
+
* and the end-user verification URI. The DeviceCode object is provided through a callback, and the end-user should be
|
|
54
|
+
* instructed to use another device to navigate to the verification URI to input credentials.
|
|
55
|
+
* Since the client cannot receive incoming requests, it polls the authorization server repeatedly
|
|
56
|
+
* until the end-user completes input of credentials.
|
|
57
|
+
*/
|
|
58
|
+
async acquireTokenByDeviceCode(request) {
|
|
59
|
+
this.logger.info("acquireTokenByDeviceCode called", request.correlationId);
|
|
60
|
+
const validRequest = Object.assign(request, await this.initializeBaseRequest(request));
|
|
61
|
+
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
|
|
62
|
+
try {
|
|
63
|
+
const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
64
|
+
const deviceCodeClient = new DeviceCodeClient(deviceCodeConfig);
|
|
65
|
+
this.logger.verbose("Device code client created", validRequest.correlationId);
|
|
66
|
+
return deviceCodeClient.acquireToken(validRequest);
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
if (e instanceof AuthError) {
|
|
70
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
71
|
+
}
|
|
72
|
+
serverTelemetryManager.cacheFailedRequest(e);
|
|
73
|
+
throw e;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
|
|
78
|
+
*/
|
|
79
|
+
async acquireTokenInteractive(request) {
|
|
80
|
+
const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
|
|
81
|
+
this.logger.trace("acquireTokenInteractive called", correlationId);
|
|
82
|
+
const { openBrowser, successTemplate, errorTemplate, windowHandle, loopbackClient: customLoopbackClient, ...remainingProperties } = request;
|
|
83
|
+
if (this.nativeBrokerPlugin) {
|
|
84
|
+
const brokerRequest = {
|
|
85
|
+
...remainingProperties,
|
|
86
|
+
clientId: this.config.auth.clientId,
|
|
87
|
+
scopes: request.scopes || OIDC_DEFAULT_SCOPES,
|
|
88
|
+
redirectUri: `${Constants$1.HTTP_PROTOCOL}${Constants$1.LOCALHOST}`,
|
|
89
|
+
authority: request.authority || this.config.auth.authority,
|
|
90
|
+
correlationId: correlationId,
|
|
91
|
+
extraParameters: {
|
|
92
|
+
...remainingProperties.extraQueryParameters,
|
|
93
|
+
...remainingProperties.tokenQueryParameters,
|
|
94
|
+
},
|
|
95
|
+
accountId: remainingProperties.account?.nativeAccountId,
|
|
96
|
+
};
|
|
97
|
+
return this.nativeBrokerPlugin.acquireTokenInteractive(brokerRequest, windowHandle);
|
|
98
|
+
}
|
|
99
|
+
const { verifier, challenge } = await this.cryptoProvider.generatePkceCodes();
|
|
100
|
+
const loopbackClient = customLoopbackClient || new LoopbackClient();
|
|
101
|
+
let authCodeResponse = {};
|
|
102
|
+
let authCodeListenerError = null;
|
|
103
|
+
try {
|
|
104
|
+
const authCodeListener = loopbackClient
|
|
105
|
+
.listenForAuthCode(successTemplate, errorTemplate)
|
|
106
|
+
.then((response) => {
|
|
107
|
+
authCodeResponse = response;
|
|
108
|
+
})
|
|
109
|
+
.catch((e) => {
|
|
110
|
+
// Store the promise instead of throwing so we can control when its thrown
|
|
111
|
+
authCodeListenerError = e;
|
|
112
|
+
});
|
|
113
|
+
// Wait for server to be listening
|
|
114
|
+
const redirectUri = await this.waitForRedirectUri(loopbackClient);
|
|
115
|
+
const validRequest = {
|
|
116
|
+
...remainingProperties,
|
|
117
|
+
correlationId: correlationId,
|
|
118
|
+
scopes: request.scopes || OIDC_DEFAULT_SCOPES,
|
|
119
|
+
redirectUri: redirectUri,
|
|
120
|
+
responseMode: ResponseMode.QUERY,
|
|
121
|
+
codeChallenge: challenge,
|
|
122
|
+
codeChallengeMethod: CodeChallengeMethodValues.S256,
|
|
123
|
+
};
|
|
124
|
+
const authCodeUrl = await this.getAuthCodeUrl(validRequest);
|
|
125
|
+
await openBrowser(authCodeUrl);
|
|
126
|
+
await authCodeListener;
|
|
127
|
+
if (authCodeListenerError) {
|
|
128
|
+
throw authCodeListenerError;
|
|
129
|
+
}
|
|
130
|
+
if (authCodeResponse.error) {
|
|
131
|
+
throw new ServerError(authCodeResponse.error, authCodeResponse.error_description, authCodeResponse.suberror);
|
|
132
|
+
}
|
|
133
|
+
else if (!authCodeResponse.code) {
|
|
134
|
+
throw NodeAuthError.createNoAuthCodeInResponseError();
|
|
135
|
+
}
|
|
136
|
+
const clientInfo = authCodeResponse.client_info;
|
|
137
|
+
const tokenRequest = {
|
|
138
|
+
code: authCodeResponse.code,
|
|
139
|
+
codeVerifier: verifier,
|
|
140
|
+
clientInfo: clientInfo || Constants.EMPTY_STRING,
|
|
141
|
+
...validRequest,
|
|
142
|
+
};
|
|
143
|
+
return this.acquireTokenByCode(tokenRequest);
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
loopbackClient.closeServer();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Returns a token retrieved either from the cache or by exchanging the refresh token for a fresh access token. If brokering is enabled the token request will be serviced by the broker.
|
|
151
|
+
* @param request
|
|
152
|
+
* @returns
|
|
153
|
+
*/
|
|
154
|
+
async acquireTokenSilent(request) {
|
|
155
|
+
const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
|
|
156
|
+
this.logger.trace("acquireTokenSilent called", correlationId);
|
|
157
|
+
if (this.nativeBrokerPlugin) {
|
|
158
|
+
const brokerRequest = {
|
|
159
|
+
...request,
|
|
160
|
+
clientId: this.config.auth.clientId,
|
|
161
|
+
scopes: request.scopes || OIDC_DEFAULT_SCOPES,
|
|
162
|
+
redirectUri: `${Constants$1.HTTP_PROTOCOL}${Constants$1.LOCALHOST}`,
|
|
163
|
+
authority: request.authority || this.config.auth.authority,
|
|
164
|
+
correlationId: correlationId,
|
|
165
|
+
extraParameters: request.tokenQueryParameters,
|
|
166
|
+
accountId: request.account.nativeAccountId,
|
|
167
|
+
forceRefresh: request.forceRefresh || false,
|
|
168
|
+
};
|
|
169
|
+
return this.nativeBrokerPlugin.acquireTokenSilent(brokerRequest);
|
|
170
|
+
}
|
|
171
|
+
return super.acquireTokenSilent(request);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Removes cache artifacts associated with the given account
|
|
175
|
+
* @param request
|
|
176
|
+
* @returns
|
|
177
|
+
*/
|
|
178
|
+
async signOut(request) {
|
|
179
|
+
if (this.nativeBrokerPlugin && request.account.nativeAccountId) {
|
|
180
|
+
const signoutRequest = {
|
|
181
|
+
clientId: this.config.auth.clientId,
|
|
182
|
+
accountId: request.account.nativeAccountId,
|
|
183
|
+
correlationId: request.correlationId ||
|
|
184
|
+
this.cryptoProvider.createNewGuid(),
|
|
185
|
+
};
|
|
186
|
+
await this.nativeBrokerPlugin.signOut(signoutRequest);
|
|
187
|
+
}
|
|
188
|
+
await this.getTokenCache().removeAccount(request.account);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Returns all cached accounts for this application. If brokering is enabled this request will be serviced by the broker.
|
|
192
|
+
* @returns
|
|
193
|
+
*/
|
|
194
|
+
async getAllAccounts() {
|
|
195
|
+
if (this.nativeBrokerPlugin) {
|
|
196
|
+
const correlationId = this.cryptoProvider.createNewGuid();
|
|
197
|
+
return this.nativeBrokerPlugin.getAllAccounts(this.config.auth.clientId, correlationId);
|
|
198
|
+
}
|
|
199
|
+
return this.getTokenCache().getAllAccounts();
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Attempts to retrieve the redirectUri from the loopback server. If the loopback server does not start listening for requests within the timeout this will throw.
|
|
203
|
+
* @param loopbackClient
|
|
204
|
+
* @returns
|
|
205
|
+
*/
|
|
206
|
+
async waitForRedirectUri(loopbackClient) {
|
|
207
|
+
return new Promise((resolve, reject) => {
|
|
208
|
+
let ticks = 0;
|
|
209
|
+
const id = setInterval(() => {
|
|
210
|
+
if (LOOPBACK_SERVER_CONSTANTS.TIMEOUT_MS /
|
|
211
|
+
LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS <
|
|
212
|
+
ticks) {
|
|
213
|
+
clearInterval(id);
|
|
214
|
+
reject(NodeAuthError.createLoopbackServerTimeoutError());
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
const r = loopbackClient.getRedirectUri();
|
|
219
|
+
clearInterval(id);
|
|
220
|
+
resolve(r);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
catch (e) {
|
|
224
|
+
if (e instanceof AuthError &&
|
|
225
|
+
e.errorCode ===
|
|
226
|
+
NodeAuthErrorMessage.noLoopbackServerExists.code) {
|
|
227
|
+
// Loopback server is not listening yet
|
|
228
|
+
ticks++;
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
clearInterval(id);
|
|
232
|
+
reject(e);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
}, LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
191
238
|
}
|
|
192
239
|
|
|
193
240
|
export { PublicClientApplication };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PublicClientApplication.mjs","sources":["../../src/client/PublicClientApplication.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"PublicClientApplication.mjs","sources":["../../src/client/PublicClientApplication.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;AAUA;AAeA;AACA;AACA;;;AAgBG;AACH;;AAKI,MAAA,uBAAA,SAAA,iBAAA,CAAA;;;;;;;;;;;;;;;;AAgBG;AACS;AAgBZ,IAAA,WAAA,CAAA,aAAA,EAAA;;;;;;;;AAQG,gBAAA,IAAA,CAAA,MAAA,CAAA,OAAA,CAAA,yEAAA,CAAA,CAAA;aACkC;AAsCrC,SAAA;;AAEG;;AAkGH;;;;AAIG;;AA0BH;;;;AAIG,QAAA,MAAA,sBAAA,GAAA,IAAA,CAAA,gCAAA,CAAA,KAAA,CAAA,wBAAA,EAAA,YAAA,CAAA,aAAA,CAAA,CAAA;QACU,IAAC;AAed,YAAA,MAAA,gBAAA,GAAA,MAAA,IAAA,CAAA,6BAAA,CAAA,YAAA,CAAA,SAAA,EAAA,YAAA,CAAA,aAAA,EAAA,sBAAA,EAAA,SAAA,EAAA,OAAA,CAAA,iBAAA,CAAA,CAAA;;;AAGG,YAAA,OAAA,gBAAA,CAAA,YAAA,CAAA,YAAA,CAAA,CAAA;AACG,SAAA;AAYN,QAAA,OAAA,CAAA,EAAA;;;;AAIG,YAAA,sBAAA,CAAA,kBAAA,CAAA,CAAA,CAAA,CAAA;YACW,MAAkB,CAAA,CAAA;AAsCnC,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,103 +1,103 @@
|
|
|
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
|
-
* Oauth2.0 Password grant client
|
|
13
|
-
* Note: We are only supporting public clients for password grant and for purely testing purposes
|
|
14
|
-
*/
|
|
15
|
-
class UsernamePasswordClient extends msalCommon.BaseClient {
|
|
16
|
-
constructor(configuration) {
|
|
17
|
-
super(configuration);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* API to acquire a token by passing the username and password to the service in exchage of credentials
|
|
21
|
-
* password_grant
|
|
22
|
-
* @param request
|
|
23
|
-
*/
|
|
24
|
-
async acquireToken(request) {
|
|
25
|
-
this.logger.info("in acquireToken call in username-password client");
|
|
26
|
-
const reqTimestamp = msalCommon.TimeUtils.nowSeconds();
|
|
27
|
-
const response = await this.executeTokenRequest(this.authority, request);
|
|
28
|
-
const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
|
|
29
|
-
// Validate response. This function throws a server error if an error is returned by the server.
|
|
30
|
-
responseHandler.validateTokenResponse(response.body);
|
|
31
|
-
const tokenResponse = responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request);
|
|
32
|
-
return tokenResponse;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Executes POST request to token endpoint
|
|
36
|
-
* @param authority
|
|
37
|
-
* @param request
|
|
38
|
-
*/
|
|
39
|
-
async executeTokenRequest(authority, request) {
|
|
40
|
-
const queryParametersString = this.createTokenQueryParameters(request);
|
|
41
|
-
const endpoint = msalCommon.UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
|
|
42
|
-
const requestBody = this.createTokenRequestBody(request);
|
|
43
|
-
const headers = this.createTokenRequestHeaders({
|
|
44
|
-
credential: request.username,
|
|
45
|
-
type: msalCommon.CcsCredentialType.UPN,
|
|
46
|
-
});
|
|
47
|
-
const thumbprint = {
|
|
48
|
-
clientId: this.config.authOptions.clientId,
|
|
49
|
-
authority: authority.canonicalAuthority,
|
|
50
|
-
scopes: request.scopes,
|
|
51
|
-
claims: request.claims,
|
|
52
|
-
authenticationScheme: request.authenticationScheme,
|
|
53
|
-
resourceRequestMethod: request.resourceRequestMethod,
|
|
54
|
-
resourceRequestUri: request.resourceRequestUri,
|
|
55
|
-
shrClaims: request.shrClaims,
|
|
56
|
-
sshKid: request.sshKid,
|
|
57
|
-
};
|
|
58
|
-
return this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Generates a map for all the params to be sent to the service
|
|
62
|
-
* @param request
|
|
63
|
-
*/
|
|
64
|
-
createTokenRequestBody(request) {
|
|
65
|
-
const parameterBuilder = new msalCommon.RequestParameterBuilder();
|
|
66
|
-
parameterBuilder.addClientId(this.config.authOptions.clientId);
|
|
67
|
-
parameterBuilder.addUsername(request.username);
|
|
68
|
-
parameterBuilder.addPassword(request.password);
|
|
69
|
-
parameterBuilder.addScopes(request.scopes);
|
|
70
|
-
parameterBuilder.addResponseTypeForTokenAndIdToken();
|
|
71
|
-
parameterBuilder.addGrantType(msalCommon.GrantType.RESOURCE_OWNER_PASSWORD_GRANT);
|
|
72
|
-
parameterBuilder.addClientInfo();
|
|
73
|
-
parameterBuilder.addLibraryInfo(this.config.libraryInfo);
|
|
74
|
-
parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
|
|
75
|
-
parameterBuilder.addThrottling();
|
|
76
|
-
if (this.serverTelemetryManager) {
|
|
77
|
-
parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
|
|
78
|
-
}
|
|
79
|
-
const correlationId = request.correlationId ||
|
|
80
|
-
this.config.cryptoInterface.createNewGuid();
|
|
81
|
-
parameterBuilder.addCorrelationId(correlationId);
|
|
82
|
-
if (this.config.clientCredentials.clientSecret) {
|
|
83
|
-
parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
|
|
84
|
-
}
|
|
85
|
-
if (this.config.clientCredentials.clientAssertion) {
|
|
86
|
-
const clientAssertion = this.config.clientCredentials.clientAssertion;
|
|
87
|
-
parameterBuilder.addClientAssertion(clientAssertion.assertion);
|
|
88
|
-
parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
|
|
89
|
-
}
|
|
90
|
-
if (!msalCommon.StringUtils.isEmptyObj(request.claims) ||
|
|
91
|
-
(this.config.authOptions.clientCapabilities &&
|
|
92
|
-
this.config.authOptions.clientCapabilities.length > 0)) {
|
|
93
|
-
parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
|
|
94
|
-
}
|
|
95
|
-
if (this.config.systemOptions.preventCorsPreflight &&
|
|
96
|
-
request.username) {
|
|
97
|
-
parameterBuilder.addCcsUpn(request.username);
|
|
98
|
-
}
|
|
99
|
-
return parameterBuilder.createQueryString();
|
|
100
|
-
}
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
9
|
+
* Licensed under the MIT License.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Oauth2.0 Password grant client
|
|
13
|
+
* Note: We are only supporting public clients for password grant and for purely testing purposes
|
|
14
|
+
*/
|
|
15
|
+
class UsernamePasswordClient extends msalCommon.BaseClient {
|
|
16
|
+
constructor(configuration) {
|
|
17
|
+
super(configuration);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* API to acquire a token by passing the username and password to the service in exchage of credentials
|
|
21
|
+
* password_grant
|
|
22
|
+
* @param request
|
|
23
|
+
*/
|
|
24
|
+
async acquireToken(request) {
|
|
25
|
+
this.logger.info("in acquireToken call in username-password client");
|
|
26
|
+
const reqTimestamp = msalCommon.TimeUtils.nowSeconds();
|
|
27
|
+
const response = await this.executeTokenRequest(this.authority, request);
|
|
28
|
+
const responseHandler = new msalCommon.ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
|
|
29
|
+
// Validate response. This function throws a server error if an error is returned by the server.
|
|
30
|
+
responseHandler.validateTokenResponse(response.body);
|
|
31
|
+
const tokenResponse = responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request);
|
|
32
|
+
return tokenResponse;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Executes POST request to token endpoint
|
|
36
|
+
* @param authority
|
|
37
|
+
* @param request
|
|
38
|
+
*/
|
|
39
|
+
async executeTokenRequest(authority, request) {
|
|
40
|
+
const queryParametersString = this.createTokenQueryParameters(request);
|
|
41
|
+
const endpoint = msalCommon.UrlString.appendQueryString(authority.tokenEndpoint, queryParametersString);
|
|
42
|
+
const requestBody = this.createTokenRequestBody(request);
|
|
43
|
+
const headers = this.createTokenRequestHeaders({
|
|
44
|
+
credential: request.username,
|
|
45
|
+
type: msalCommon.CcsCredentialType.UPN,
|
|
46
|
+
});
|
|
47
|
+
const thumbprint = {
|
|
48
|
+
clientId: this.config.authOptions.clientId,
|
|
49
|
+
authority: authority.canonicalAuthority,
|
|
50
|
+
scopes: request.scopes,
|
|
51
|
+
claims: request.claims,
|
|
52
|
+
authenticationScheme: request.authenticationScheme,
|
|
53
|
+
resourceRequestMethod: request.resourceRequestMethod,
|
|
54
|
+
resourceRequestUri: request.resourceRequestUri,
|
|
55
|
+
shrClaims: request.shrClaims,
|
|
56
|
+
sshKid: request.sshKid,
|
|
57
|
+
};
|
|
58
|
+
return this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint, request.correlationId);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Generates a map for all the params to be sent to the service
|
|
62
|
+
* @param request
|
|
63
|
+
*/
|
|
64
|
+
createTokenRequestBody(request) {
|
|
65
|
+
const parameterBuilder = new msalCommon.RequestParameterBuilder();
|
|
66
|
+
parameterBuilder.addClientId(this.config.authOptions.clientId);
|
|
67
|
+
parameterBuilder.addUsername(request.username);
|
|
68
|
+
parameterBuilder.addPassword(request.password);
|
|
69
|
+
parameterBuilder.addScopes(request.scopes);
|
|
70
|
+
parameterBuilder.addResponseTypeForTokenAndIdToken();
|
|
71
|
+
parameterBuilder.addGrantType(msalCommon.GrantType.RESOURCE_OWNER_PASSWORD_GRANT);
|
|
72
|
+
parameterBuilder.addClientInfo();
|
|
73
|
+
parameterBuilder.addLibraryInfo(this.config.libraryInfo);
|
|
74
|
+
parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
|
|
75
|
+
parameterBuilder.addThrottling();
|
|
76
|
+
if (this.serverTelemetryManager) {
|
|
77
|
+
parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
|
|
78
|
+
}
|
|
79
|
+
const correlationId = request.correlationId ||
|
|
80
|
+
this.config.cryptoInterface.createNewGuid();
|
|
81
|
+
parameterBuilder.addCorrelationId(correlationId);
|
|
82
|
+
if (this.config.clientCredentials.clientSecret) {
|
|
83
|
+
parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
|
|
84
|
+
}
|
|
85
|
+
if (this.config.clientCredentials.clientAssertion) {
|
|
86
|
+
const clientAssertion = this.config.clientCredentials.clientAssertion;
|
|
87
|
+
parameterBuilder.addClientAssertion(clientAssertion.assertion);
|
|
88
|
+
parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
|
|
89
|
+
}
|
|
90
|
+
if (!msalCommon.StringUtils.isEmptyObj(request.claims) ||
|
|
91
|
+
(this.config.authOptions.clientCapabilities &&
|
|
92
|
+
this.config.authOptions.clientCapabilities.length > 0)) {
|
|
93
|
+
parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
|
|
94
|
+
}
|
|
95
|
+
if (this.config.systemOptions.preventCorsPreflight &&
|
|
96
|
+
request.username) {
|
|
97
|
+
parameterBuilder.addCcsUpn(request.username);
|
|
98
|
+
}
|
|
99
|
+
return parameterBuilder.createQueryString();
|
|
100
|
+
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
exports.UsernamePasswordClient = UsernamePasswordClient;
|