@azure/msal-node 2.2.0-alpha.0 → 2.3.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.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 -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.d.ts +46 -46
- package/dist/client/ClientAssertion.mjs +116 -116
- package/dist/client/ClientCredentialClient.cjs +189 -189
- package/dist/client/ClientCredentialClient.d.ts +33 -33
- package/dist/client/ClientCredentialClient.mjs +189 -189
- package/dist/client/ConfidentialClientApplication.cjs +163 -163
- package/dist/client/ConfidentialClientApplication.d.ts +58 -58
- package/dist/client/ConfidentialClientApplication.mjs +163 -163
- package/dist/client/DeviceCodeClient.cjs +207 -207
- package/dist/client/DeviceCodeClient.d.ts +53 -53
- package/dist/client/DeviceCodeClient.mjs +207 -207
- 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.d.ts +47 -47
- package/dist/client/OnBehalfOfClient.mjs +202 -202
- package/dist/client/PublicClientApplication.cjs +229 -229
- package/dist/client/PublicClientApplication.d.ts +71 -71
- package/dist/client/PublicClientApplication.mjs +229 -229
- 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 +1 -1
- package/dist/index.d.ts +42 -42
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -1
- 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 +76 -75
- 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 -75
- package/dist/network/LoopbackClient.mjs.map +1 -1
- package/dist/packageMetadata.cjs +4 -4
- package/dist/packageMetadata.d.ts +2 -2
- package/dist/packageMetadata.mjs +4 -4
- 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/cache/NodeStorage.ts +8 -2
- package/src/client/ClientApplication.ts +3 -1
- package/src/index.ts +1 -0
- package/src/network/LoopbackClient.ts +1 -0
- package/src/packageMetadata.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @azure/msal-node v2.
|
|
1
|
+
/*! @azure/msal-node v2.3.0 2023-10-20 */
|
|
2
2
|
'use strict';
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -9,234 +9,234 @@ var NodeAuthError = require('../error/NodeAuthError.cjs');
|
|
|
9
9
|
var LoopbackClient = require('../network/LoopbackClient.cjs');
|
|
10
10
|
var DeviceCodeClient = require('./DeviceCodeClient.cjs');
|
|
11
11
|
|
|
12
|
-
/*
|
|
13
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
14
|
-
* Licensed under the MIT License.
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* This class is to be used to acquire tokens for public client applications (desktop, mobile). Public client applications
|
|
18
|
-
* are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
21
|
-
class PublicClientApplication extends ClientApplication.ClientApplication {
|
|
22
|
-
/**
|
|
23
|
-
* Important attributes in the Configuration object for auth are:
|
|
24
|
-
* - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal.
|
|
25
|
-
* - authority: the authority URL for your application.
|
|
26
|
-
*
|
|
27
|
-
* AAD authorities are of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
|
|
28
|
-
* - 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).
|
|
29
|
-
* - If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
|
|
30
|
-
* - If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
|
|
31
|
-
* - To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
|
|
32
|
-
*
|
|
33
|
-
* Azure B2C authorities are of the form https://\{instance\}/\{tenant\}/\{policy\}. Each policy is considered
|
|
34
|
-
* its own authority. You will have to set the all of the knownAuthorities at the time of the client application
|
|
35
|
-
* construction.
|
|
36
|
-
*
|
|
37
|
-
* ADFS authorities are of the form https://\{instance\}/adfs.
|
|
38
|
-
*/
|
|
39
|
-
constructor(configuration) {
|
|
40
|
-
super(configuration);
|
|
41
|
-
if (this.config.broker.nativeBrokerPlugin) {
|
|
42
|
-
if (this.config.broker.nativeBrokerPlugin.isBrokerAvailable) {
|
|
43
|
-
this.nativeBrokerPlugin = this.config.broker.nativeBrokerPlugin;
|
|
44
|
-
this.nativeBrokerPlugin.setLogger(this.config.system.loggerOptions);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
this.logger.warning("NativeBroker implementation was provided but the broker is unavailable.");
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Acquires a token from the authority using OAuth2.0 device code flow.
|
|
53
|
-
* This flow is designed for devices that do not have access to a browser or have input constraints.
|
|
54
|
-
* The authorization server issues a DeviceCode object with a verification code, an end-user code,
|
|
55
|
-
* and the end-user verification URI. The DeviceCode object is provided through a callback, and the end-user should be
|
|
56
|
-
* instructed to use another device to navigate to the verification URI to input credentials.
|
|
57
|
-
* Since the client cannot receive incoming requests, it polls the authorization server repeatedly
|
|
58
|
-
* until the end-user completes input of credentials.
|
|
59
|
-
*/
|
|
60
|
-
async acquireTokenByDeviceCode(request) {
|
|
61
|
-
this.logger.info("acquireTokenByDeviceCode called", request.correlationId);
|
|
62
|
-
const validRequest = Object.assign(request, await this.initializeBaseRequest(request));
|
|
63
|
-
const serverTelemetryManager = this.initializeServerTelemetryManager(Constants.ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
|
|
64
|
-
try {
|
|
65
|
-
const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
66
|
-
const deviceCodeClient = new DeviceCodeClient.DeviceCodeClient(deviceCodeConfig);
|
|
67
|
-
this.logger.verbose("Device code client created", validRequest.correlationId);
|
|
68
|
-
return deviceCodeClient.acquireToken(validRequest);
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
if (e instanceof msalCommon.AuthError) {
|
|
72
|
-
e.setCorrelationId(validRequest.correlationId);
|
|
73
|
-
}
|
|
74
|
-
serverTelemetryManager.cacheFailedRequest(e);
|
|
75
|
-
throw e;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
|
|
80
|
-
*/
|
|
81
|
-
async acquireTokenInteractive(request) {
|
|
82
|
-
const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
|
|
83
|
-
this.logger.trace("acquireTokenInteractive called", correlationId);
|
|
84
|
-
const { openBrowser, successTemplate, errorTemplate, windowHandle, loopbackClient: customLoopbackClient, ...remainingProperties } = request;
|
|
85
|
-
if (this.nativeBrokerPlugin) {
|
|
86
|
-
const brokerRequest = {
|
|
87
|
-
...remainingProperties,
|
|
88
|
-
clientId: this.config.auth.clientId,
|
|
89
|
-
scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
|
|
90
|
-
redirectUri: `${Constants.Constants.HTTP_PROTOCOL}${Constants.Constants.LOCALHOST}`,
|
|
91
|
-
authority: request.authority || this.config.auth.authority,
|
|
92
|
-
correlationId: correlationId,
|
|
93
|
-
extraParameters: {
|
|
94
|
-
...remainingProperties.extraQueryParameters,
|
|
95
|
-
...remainingProperties.tokenQueryParameters,
|
|
96
|
-
},
|
|
97
|
-
accountId: remainingProperties.account?.nativeAccountId,
|
|
98
|
-
};
|
|
99
|
-
return this.nativeBrokerPlugin.acquireTokenInteractive(brokerRequest, windowHandle);
|
|
100
|
-
}
|
|
101
|
-
const { verifier, challenge } = await this.cryptoProvider.generatePkceCodes();
|
|
102
|
-
const loopbackClient = customLoopbackClient || new LoopbackClient.LoopbackClient();
|
|
103
|
-
let authCodeResponse = {};
|
|
104
|
-
let authCodeListenerError = null;
|
|
105
|
-
try {
|
|
106
|
-
const authCodeListener = loopbackClient
|
|
107
|
-
.listenForAuthCode(successTemplate, errorTemplate)
|
|
108
|
-
.then((response) => {
|
|
109
|
-
authCodeResponse = response;
|
|
110
|
-
})
|
|
111
|
-
.catch((e) => {
|
|
112
|
-
// Store the promise instead of throwing so we can control when its thrown
|
|
113
|
-
authCodeListenerError = e;
|
|
114
|
-
});
|
|
115
|
-
// Wait for server to be listening
|
|
116
|
-
const redirectUri = await this.waitForRedirectUri(loopbackClient);
|
|
117
|
-
const validRequest = {
|
|
118
|
-
...remainingProperties,
|
|
119
|
-
correlationId: correlationId,
|
|
120
|
-
scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
|
|
121
|
-
redirectUri: redirectUri,
|
|
122
|
-
responseMode: msalCommon.ResponseMode.QUERY,
|
|
123
|
-
codeChallenge: challenge,
|
|
124
|
-
codeChallengeMethod: msalCommon.CodeChallengeMethodValues.S256,
|
|
125
|
-
};
|
|
126
|
-
const authCodeUrl = await this.getAuthCodeUrl(validRequest);
|
|
127
|
-
await openBrowser(authCodeUrl);
|
|
128
|
-
await authCodeListener;
|
|
129
|
-
if (authCodeListenerError) {
|
|
130
|
-
throw authCodeListenerError;
|
|
131
|
-
}
|
|
132
|
-
if (authCodeResponse.error) {
|
|
133
|
-
throw new msalCommon.ServerError(authCodeResponse.error, authCodeResponse.error_description, authCodeResponse.suberror);
|
|
134
|
-
}
|
|
135
|
-
else if (!authCodeResponse.code) {
|
|
136
|
-
throw NodeAuthError.NodeAuthError.createNoAuthCodeInResponseError();
|
|
137
|
-
}
|
|
138
|
-
const clientInfo = authCodeResponse.client_info;
|
|
139
|
-
const tokenRequest = {
|
|
140
|
-
code: authCodeResponse.code,
|
|
141
|
-
codeVerifier: verifier,
|
|
142
|
-
clientInfo: clientInfo || msalCommon.Constants.EMPTY_STRING,
|
|
143
|
-
...validRequest,
|
|
144
|
-
};
|
|
145
|
-
return this.acquireTokenByCode(tokenRequest);
|
|
146
|
-
}
|
|
147
|
-
finally {
|
|
148
|
-
loopbackClient.closeServer();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* 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.
|
|
153
|
-
* @param request
|
|
154
|
-
* @returns
|
|
155
|
-
*/
|
|
156
|
-
async acquireTokenSilent(request) {
|
|
157
|
-
const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
|
|
158
|
-
this.logger.trace("acquireTokenSilent called", correlationId);
|
|
159
|
-
if (this.nativeBrokerPlugin) {
|
|
160
|
-
const brokerRequest = {
|
|
161
|
-
...request,
|
|
162
|
-
clientId: this.config.auth.clientId,
|
|
163
|
-
scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
|
|
164
|
-
redirectUri: `${Constants.Constants.HTTP_PROTOCOL}${Constants.Constants.LOCALHOST}`,
|
|
165
|
-
authority: request.authority || this.config.auth.authority,
|
|
166
|
-
correlationId: correlationId,
|
|
167
|
-
extraParameters: request.tokenQueryParameters,
|
|
168
|
-
accountId: request.account.nativeAccountId,
|
|
169
|
-
forceRefresh: request.forceRefresh || false,
|
|
170
|
-
};
|
|
171
|
-
return this.nativeBrokerPlugin.acquireTokenSilent(brokerRequest);
|
|
172
|
-
}
|
|
173
|
-
return super.acquireTokenSilent(request);
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Removes cache artifacts associated with the given account
|
|
177
|
-
* @param request
|
|
178
|
-
* @returns
|
|
179
|
-
*/
|
|
180
|
-
async signOut(request) {
|
|
181
|
-
if (this.nativeBrokerPlugin && request.account.nativeAccountId) {
|
|
182
|
-
const signoutRequest = {
|
|
183
|
-
clientId: this.config.auth.clientId,
|
|
184
|
-
accountId: request.account.nativeAccountId,
|
|
185
|
-
correlationId: request.correlationId ||
|
|
186
|
-
this.cryptoProvider.createNewGuid(),
|
|
187
|
-
};
|
|
188
|
-
await this.nativeBrokerPlugin.signOut(signoutRequest);
|
|
189
|
-
}
|
|
190
|
-
await this.getTokenCache().removeAccount(request.account);
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Returns all cached accounts for this application. If brokering is enabled this request will be serviced by the broker.
|
|
194
|
-
* @returns
|
|
195
|
-
*/
|
|
196
|
-
async getAllAccounts() {
|
|
197
|
-
if (this.nativeBrokerPlugin) {
|
|
198
|
-
const correlationId = this.cryptoProvider.createNewGuid();
|
|
199
|
-
return this.nativeBrokerPlugin.getAllAccounts(this.config.auth.clientId, correlationId);
|
|
200
|
-
}
|
|
201
|
-
return this.getTokenCache().getAllAccounts();
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* 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.
|
|
205
|
-
* @param loopbackClient
|
|
206
|
-
* @returns
|
|
207
|
-
*/
|
|
208
|
-
async waitForRedirectUri(loopbackClient) {
|
|
209
|
-
return new Promise((resolve, reject) => {
|
|
210
|
-
let ticks = 0;
|
|
211
|
-
const id = setInterval(() => {
|
|
212
|
-
if (Constants.LOOPBACK_SERVER_CONSTANTS.TIMEOUT_MS /
|
|
213
|
-
Constants.LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS <
|
|
214
|
-
ticks) {
|
|
215
|
-
clearInterval(id);
|
|
216
|
-
reject(NodeAuthError.NodeAuthError.createLoopbackServerTimeoutError());
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
try {
|
|
220
|
-
const r = loopbackClient.getRedirectUri();
|
|
221
|
-
clearInterval(id);
|
|
222
|
-
resolve(r);
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
catch (e) {
|
|
226
|
-
if (e instanceof msalCommon.AuthError &&
|
|
227
|
-
e.errorCode ===
|
|
228
|
-
NodeAuthError.NodeAuthErrorMessage.noLoopbackServerExists.code) {
|
|
229
|
-
// Loopback server is not listening yet
|
|
230
|
-
ticks++;
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
clearInterval(id);
|
|
234
|
-
reject(e);
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
}, Constants.LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS);
|
|
238
|
-
});
|
|
239
|
-
}
|
|
12
|
+
/*
|
|
13
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
14
|
+
* Licensed under the MIT License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* This class is to be used to acquire tokens for public client applications (desktop, mobile). Public client applications
|
|
18
|
+
* are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
class PublicClientApplication extends ClientApplication.ClientApplication {
|
|
22
|
+
/**
|
|
23
|
+
* Important attributes in the Configuration object for auth are:
|
|
24
|
+
* - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal.
|
|
25
|
+
* - authority: the authority URL for your application.
|
|
26
|
+
*
|
|
27
|
+
* AAD authorities are of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
|
|
28
|
+
* - 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).
|
|
29
|
+
* - If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
|
|
30
|
+
* - If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
|
|
31
|
+
* - To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
|
|
32
|
+
*
|
|
33
|
+
* Azure B2C authorities are of the form https://\{instance\}/\{tenant\}/\{policy\}. Each policy is considered
|
|
34
|
+
* its own authority. You will have to set the all of the knownAuthorities at the time of the client application
|
|
35
|
+
* construction.
|
|
36
|
+
*
|
|
37
|
+
* ADFS authorities are of the form https://\{instance\}/adfs.
|
|
38
|
+
*/
|
|
39
|
+
constructor(configuration) {
|
|
40
|
+
super(configuration);
|
|
41
|
+
if (this.config.broker.nativeBrokerPlugin) {
|
|
42
|
+
if (this.config.broker.nativeBrokerPlugin.isBrokerAvailable) {
|
|
43
|
+
this.nativeBrokerPlugin = this.config.broker.nativeBrokerPlugin;
|
|
44
|
+
this.nativeBrokerPlugin.setLogger(this.config.system.loggerOptions);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this.logger.warning("NativeBroker implementation was provided but the broker is unavailable.");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Acquires a token from the authority using OAuth2.0 device code flow.
|
|
53
|
+
* This flow is designed for devices that do not have access to a browser or have input constraints.
|
|
54
|
+
* The authorization server issues a DeviceCode object with a verification code, an end-user code,
|
|
55
|
+
* and the end-user verification URI. The DeviceCode object is provided through a callback, and the end-user should be
|
|
56
|
+
* instructed to use another device to navigate to the verification URI to input credentials.
|
|
57
|
+
* Since the client cannot receive incoming requests, it polls the authorization server repeatedly
|
|
58
|
+
* until the end-user completes input of credentials.
|
|
59
|
+
*/
|
|
60
|
+
async acquireTokenByDeviceCode(request) {
|
|
61
|
+
this.logger.info("acquireTokenByDeviceCode called", request.correlationId);
|
|
62
|
+
const validRequest = Object.assign(request, await this.initializeBaseRequest(request));
|
|
63
|
+
const serverTelemetryManager = this.initializeServerTelemetryManager(Constants.ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
|
|
64
|
+
try {
|
|
65
|
+
const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
66
|
+
const deviceCodeClient = new DeviceCodeClient.DeviceCodeClient(deviceCodeConfig);
|
|
67
|
+
this.logger.verbose("Device code client created", validRequest.correlationId);
|
|
68
|
+
return deviceCodeClient.acquireToken(validRequest);
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
if (e instanceof msalCommon.AuthError) {
|
|
72
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
73
|
+
}
|
|
74
|
+
serverTelemetryManager.cacheFailedRequest(e);
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
|
|
80
|
+
*/
|
|
81
|
+
async acquireTokenInteractive(request) {
|
|
82
|
+
const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
|
|
83
|
+
this.logger.trace("acquireTokenInteractive called", correlationId);
|
|
84
|
+
const { openBrowser, successTemplate, errorTemplate, windowHandle, loopbackClient: customLoopbackClient, ...remainingProperties } = request;
|
|
85
|
+
if (this.nativeBrokerPlugin) {
|
|
86
|
+
const brokerRequest = {
|
|
87
|
+
...remainingProperties,
|
|
88
|
+
clientId: this.config.auth.clientId,
|
|
89
|
+
scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
|
|
90
|
+
redirectUri: `${Constants.Constants.HTTP_PROTOCOL}${Constants.Constants.LOCALHOST}`,
|
|
91
|
+
authority: request.authority || this.config.auth.authority,
|
|
92
|
+
correlationId: correlationId,
|
|
93
|
+
extraParameters: {
|
|
94
|
+
...remainingProperties.extraQueryParameters,
|
|
95
|
+
...remainingProperties.tokenQueryParameters,
|
|
96
|
+
},
|
|
97
|
+
accountId: remainingProperties.account?.nativeAccountId,
|
|
98
|
+
};
|
|
99
|
+
return this.nativeBrokerPlugin.acquireTokenInteractive(brokerRequest, windowHandle);
|
|
100
|
+
}
|
|
101
|
+
const { verifier, challenge } = await this.cryptoProvider.generatePkceCodes();
|
|
102
|
+
const loopbackClient = customLoopbackClient || new LoopbackClient.LoopbackClient();
|
|
103
|
+
let authCodeResponse = {};
|
|
104
|
+
let authCodeListenerError = null;
|
|
105
|
+
try {
|
|
106
|
+
const authCodeListener = loopbackClient
|
|
107
|
+
.listenForAuthCode(successTemplate, errorTemplate)
|
|
108
|
+
.then((response) => {
|
|
109
|
+
authCodeResponse = response;
|
|
110
|
+
})
|
|
111
|
+
.catch((e) => {
|
|
112
|
+
// Store the promise instead of throwing so we can control when its thrown
|
|
113
|
+
authCodeListenerError = e;
|
|
114
|
+
});
|
|
115
|
+
// Wait for server to be listening
|
|
116
|
+
const redirectUri = await this.waitForRedirectUri(loopbackClient);
|
|
117
|
+
const validRequest = {
|
|
118
|
+
...remainingProperties,
|
|
119
|
+
correlationId: correlationId,
|
|
120
|
+
scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
|
|
121
|
+
redirectUri: redirectUri,
|
|
122
|
+
responseMode: msalCommon.ResponseMode.QUERY,
|
|
123
|
+
codeChallenge: challenge,
|
|
124
|
+
codeChallengeMethod: msalCommon.CodeChallengeMethodValues.S256,
|
|
125
|
+
};
|
|
126
|
+
const authCodeUrl = await this.getAuthCodeUrl(validRequest);
|
|
127
|
+
await openBrowser(authCodeUrl);
|
|
128
|
+
await authCodeListener;
|
|
129
|
+
if (authCodeListenerError) {
|
|
130
|
+
throw authCodeListenerError;
|
|
131
|
+
}
|
|
132
|
+
if (authCodeResponse.error) {
|
|
133
|
+
throw new msalCommon.ServerError(authCodeResponse.error, authCodeResponse.error_description, authCodeResponse.suberror);
|
|
134
|
+
}
|
|
135
|
+
else if (!authCodeResponse.code) {
|
|
136
|
+
throw NodeAuthError.NodeAuthError.createNoAuthCodeInResponseError();
|
|
137
|
+
}
|
|
138
|
+
const clientInfo = authCodeResponse.client_info;
|
|
139
|
+
const tokenRequest = {
|
|
140
|
+
code: authCodeResponse.code,
|
|
141
|
+
codeVerifier: verifier,
|
|
142
|
+
clientInfo: clientInfo || msalCommon.Constants.EMPTY_STRING,
|
|
143
|
+
...validRequest,
|
|
144
|
+
};
|
|
145
|
+
return this.acquireTokenByCode(tokenRequest);
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
loopbackClient.closeServer();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* 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.
|
|
153
|
+
* @param request
|
|
154
|
+
* @returns
|
|
155
|
+
*/
|
|
156
|
+
async acquireTokenSilent(request) {
|
|
157
|
+
const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
|
|
158
|
+
this.logger.trace("acquireTokenSilent called", correlationId);
|
|
159
|
+
if (this.nativeBrokerPlugin) {
|
|
160
|
+
const brokerRequest = {
|
|
161
|
+
...request,
|
|
162
|
+
clientId: this.config.auth.clientId,
|
|
163
|
+
scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
|
|
164
|
+
redirectUri: `${Constants.Constants.HTTP_PROTOCOL}${Constants.Constants.LOCALHOST}`,
|
|
165
|
+
authority: request.authority || this.config.auth.authority,
|
|
166
|
+
correlationId: correlationId,
|
|
167
|
+
extraParameters: request.tokenQueryParameters,
|
|
168
|
+
accountId: request.account.nativeAccountId,
|
|
169
|
+
forceRefresh: request.forceRefresh || false,
|
|
170
|
+
};
|
|
171
|
+
return this.nativeBrokerPlugin.acquireTokenSilent(brokerRequest);
|
|
172
|
+
}
|
|
173
|
+
return super.acquireTokenSilent(request);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Removes cache artifacts associated with the given account
|
|
177
|
+
* @param request
|
|
178
|
+
* @returns
|
|
179
|
+
*/
|
|
180
|
+
async signOut(request) {
|
|
181
|
+
if (this.nativeBrokerPlugin && request.account.nativeAccountId) {
|
|
182
|
+
const signoutRequest = {
|
|
183
|
+
clientId: this.config.auth.clientId,
|
|
184
|
+
accountId: request.account.nativeAccountId,
|
|
185
|
+
correlationId: request.correlationId ||
|
|
186
|
+
this.cryptoProvider.createNewGuid(),
|
|
187
|
+
};
|
|
188
|
+
await this.nativeBrokerPlugin.signOut(signoutRequest);
|
|
189
|
+
}
|
|
190
|
+
await this.getTokenCache().removeAccount(request.account);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Returns all cached accounts for this application. If brokering is enabled this request will be serviced by the broker.
|
|
194
|
+
* @returns
|
|
195
|
+
*/
|
|
196
|
+
async getAllAccounts() {
|
|
197
|
+
if (this.nativeBrokerPlugin) {
|
|
198
|
+
const correlationId = this.cryptoProvider.createNewGuid();
|
|
199
|
+
return this.nativeBrokerPlugin.getAllAccounts(this.config.auth.clientId, correlationId);
|
|
200
|
+
}
|
|
201
|
+
return this.getTokenCache().getAllAccounts();
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* 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.
|
|
205
|
+
* @param loopbackClient
|
|
206
|
+
* @returns
|
|
207
|
+
*/
|
|
208
|
+
async waitForRedirectUri(loopbackClient) {
|
|
209
|
+
return new Promise((resolve, reject) => {
|
|
210
|
+
let ticks = 0;
|
|
211
|
+
const id = setInterval(() => {
|
|
212
|
+
if (Constants.LOOPBACK_SERVER_CONSTANTS.TIMEOUT_MS /
|
|
213
|
+
Constants.LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS <
|
|
214
|
+
ticks) {
|
|
215
|
+
clearInterval(id);
|
|
216
|
+
reject(NodeAuthError.NodeAuthError.createLoopbackServerTimeoutError());
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
const r = loopbackClient.getRedirectUri();
|
|
221
|
+
clearInterval(id);
|
|
222
|
+
resolve(r);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
catch (e) {
|
|
226
|
+
if (e instanceof msalCommon.AuthError &&
|
|
227
|
+
e.errorCode ===
|
|
228
|
+
NodeAuthError.NodeAuthErrorMessage.noLoopbackServerExists.code) {
|
|
229
|
+
// Loopback server is not listening yet
|
|
230
|
+
ticks++;
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
clearInterval(id);
|
|
234
|
+
reject(e);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
}, Constants.LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
exports.PublicClientApplication = PublicClientApplication;
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { AuthenticationResult, AccountInfo } from "@azure/msal-common";
|
|
2
|
-
import { Configuration } from "../config/Configuration.js";
|
|
3
|
-
import { ClientApplication } from "./ClientApplication.js";
|
|
4
|
-
import { IPublicClientApplication } from "./IPublicClientApplication.js";
|
|
5
|
-
import { DeviceCodeRequest } from "../request/DeviceCodeRequest.js";
|
|
6
|
-
import { InteractiveRequest } from "../request/InteractiveRequest.js";
|
|
7
|
-
import { SilentFlowRequest } from "../request/SilentFlowRequest.js";
|
|
8
|
-
import { SignOutRequest } from "../request/SignOutRequest.js";
|
|
9
|
-
/**
|
|
10
|
-
* This class is to be used to acquire tokens for public client applications (desktop, mobile). Public client applications
|
|
11
|
-
* are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
14
|
-
export declare class PublicClientApplication extends ClientApplication implements IPublicClientApplication {
|
|
15
|
-
private nativeBrokerPlugin?;
|
|
16
|
-
/**
|
|
17
|
-
* Important attributes in the Configuration object for auth are:
|
|
18
|
-
* - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal.
|
|
19
|
-
* - authority: the authority URL for your application.
|
|
20
|
-
*
|
|
21
|
-
* AAD authorities are of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
|
|
22
|
-
* - 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).
|
|
23
|
-
* - If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
|
|
24
|
-
* - If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
|
|
25
|
-
* - To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
|
|
26
|
-
*
|
|
27
|
-
* Azure B2C authorities are of the form https://\{instance\}/\{tenant\}/\{policy\}. Each policy is considered
|
|
28
|
-
* its own authority. You will have to set the all of the knownAuthorities at the time of the client application
|
|
29
|
-
* construction.
|
|
30
|
-
*
|
|
31
|
-
* ADFS authorities are of the form https://\{instance\}/adfs.
|
|
32
|
-
*/
|
|
33
|
-
constructor(configuration: Configuration);
|
|
34
|
-
/**
|
|
35
|
-
* Acquires a token from the authority using OAuth2.0 device code flow.
|
|
36
|
-
* This flow is designed for devices that do not have access to a browser or have input constraints.
|
|
37
|
-
* The authorization server issues a DeviceCode object with a verification code, an end-user code,
|
|
38
|
-
* and the end-user verification URI. The DeviceCode object is provided through a callback, and the end-user should be
|
|
39
|
-
* instructed to use another device to navigate to the verification URI to input credentials.
|
|
40
|
-
* Since the client cannot receive incoming requests, it polls the authorization server repeatedly
|
|
41
|
-
* until the end-user completes input of credentials.
|
|
42
|
-
*/
|
|
43
|
-
acquireTokenByDeviceCode(request: DeviceCodeRequest): Promise<AuthenticationResult | null>;
|
|
44
|
-
/**
|
|
45
|
-
* Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
|
|
46
|
-
*/
|
|
47
|
-
acquireTokenInteractive(request: InteractiveRequest): Promise<AuthenticationResult>;
|
|
48
|
-
/**
|
|
49
|
-
* 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.
|
|
50
|
-
* @param request
|
|
51
|
-
* @returns
|
|
52
|
-
*/
|
|
53
|
-
acquireTokenSilent(request: SilentFlowRequest): Promise<AuthenticationResult>;
|
|
54
|
-
/**
|
|
55
|
-
* Removes cache artifacts associated with the given account
|
|
56
|
-
* @param request
|
|
57
|
-
* @returns
|
|
58
|
-
*/
|
|
59
|
-
signOut(request: SignOutRequest): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Returns all cached accounts for this application. If brokering is enabled this request will be serviced by the broker.
|
|
62
|
-
* @returns
|
|
63
|
-
*/
|
|
64
|
-
getAllAccounts(): Promise<AccountInfo[]>;
|
|
65
|
-
/**
|
|
66
|
-
* 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.
|
|
67
|
-
* @param loopbackClient
|
|
68
|
-
* @returns
|
|
69
|
-
*/
|
|
70
|
-
private waitForRedirectUri;
|
|
71
|
-
}
|
|
1
|
+
import { AuthenticationResult, AccountInfo } from "@azure/msal-common";
|
|
2
|
+
import { Configuration } from "../config/Configuration.js";
|
|
3
|
+
import { ClientApplication } from "./ClientApplication.js";
|
|
4
|
+
import { IPublicClientApplication } from "./IPublicClientApplication.js";
|
|
5
|
+
import { DeviceCodeRequest } from "../request/DeviceCodeRequest.js";
|
|
6
|
+
import { InteractiveRequest } from "../request/InteractiveRequest.js";
|
|
7
|
+
import { SilentFlowRequest } from "../request/SilentFlowRequest.js";
|
|
8
|
+
import { SignOutRequest } from "../request/SignOutRequest.js";
|
|
9
|
+
/**
|
|
10
|
+
* This class is to be used to acquire tokens for public client applications (desktop, mobile). Public client applications
|
|
11
|
+
* are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export declare class PublicClientApplication extends ClientApplication implements IPublicClientApplication {
|
|
15
|
+
private nativeBrokerPlugin?;
|
|
16
|
+
/**
|
|
17
|
+
* Important attributes in the Configuration object for auth are:
|
|
18
|
+
* - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal.
|
|
19
|
+
* - authority: the authority URL for your application.
|
|
20
|
+
*
|
|
21
|
+
* AAD authorities are of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
|
|
22
|
+
* - 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).
|
|
23
|
+
* - If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
|
|
24
|
+
* - If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
|
|
25
|
+
* - To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
|
|
26
|
+
*
|
|
27
|
+
* Azure B2C authorities are of the form https://\{instance\}/\{tenant\}/\{policy\}. Each policy is considered
|
|
28
|
+
* its own authority. You will have to set the all of the knownAuthorities at the time of the client application
|
|
29
|
+
* construction.
|
|
30
|
+
*
|
|
31
|
+
* ADFS authorities are of the form https://\{instance\}/adfs.
|
|
32
|
+
*/
|
|
33
|
+
constructor(configuration: Configuration);
|
|
34
|
+
/**
|
|
35
|
+
* Acquires a token from the authority using OAuth2.0 device code flow.
|
|
36
|
+
* This flow is designed for devices that do not have access to a browser or have input constraints.
|
|
37
|
+
* The authorization server issues a DeviceCode object with a verification code, an end-user code,
|
|
38
|
+
* and the end-user verification URI. The DeviceCode object is provided through a callback, and the end-user should be
|
|
39
|
+
* instructed to use another device to navigate to the verification URI to input credentials.
|
|
40
|
+
* Since the client cannot receive incoming requests, it polls the authorization server repeatedly
|
|
41
|
+
* until the end-user completes input of credentials.
|
|
42
|
+
*/
|
|
43
|
+
acquireTokenByDeviceCode(request: DeviceCodeRequest): Promise<AuthenticationResult | null>;
|
|
44
|
+
/**
|
|
45
|
+
* Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
|
|
46
|
+
*/
|
|
47
|
+
acquireTokenInteractive(request: InteractiveRequest): Promise<AuthenticationResult>;
|
|
48
|
+
/**
|
|
49
|
+
* 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.
|
|
50
|
+
* @param request
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
acquireTokenSilent(request: SilentFlowRequest): Promise<AuthenticationResult>;
|
|
54
|
+
/**
|
|
55
|
+
* Removes cache artifacts associated with the given account
|
|
56
|
+
* @param request
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
signOut(request: SignOutRequest): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Returns all cached accounts for this application. If brokering is enabled this request will be serviced by the broker.
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
getAllAccounts(): Promise<AccountInfo[]>;
|
|
65
|
+
/**
|
|
66
|
+
* 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.
|
|
67
|
+
* @param loopbackClient
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
private waitForRedirectUri;
|
|
71
|
+
}
|
|
72
72
|
//# sourceMappingURL=PublicClientApplication.d.ts.map
|