@azure/identity 2.0.0-beta.2 → 2.0.0-beta.6
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.
Potentially problematic release.
This version of @azure/identity might be problematic. Click here for more details.
- package/CHANGELOG.md +127 -8
- package/README.md +88 -45
- package/dist/index.js +2237 -1675
- package/dist/index.js.map +1 -1
- package/dist-esm/src/client/errors.js +1 -1
- package/dist-esm/src/client/errors.js.map +1 -1
- package/dist-esm/src/client/identityClient.js +146 -132
- package/dist-esm/src/client/identityClient.js.map +1 -1
- package/dist-esm/src/constants.js +1 -1
- package/dist-esm/src/constants.js.map +1 -1
- package/dist-esm/src/credentials/applicationCredential.browser.js +29 -0
- package/dist-esm/src/credentials/applicationCredential.browser.js.map +1 -0
- package/dist-esm/src/credentials/applicationCredential.js +34 -0
- package/dist-esm/src/credentials/applicationCredential.js.map +1 -0
- package/dist-esm/src/credentials/authorizationCodeCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/authorizationCodeCredential.js +13 -76
- package/dist-esm/src/credentials/authorizationCodeCredential.js.map +1 -1
- package/dist-esm/src/credentials/azureCliCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/azureCliCredential.js +104 -81
- package/dist-esm/src/credentials/azureCliCredential.js.map +1 -1
- package/dist-esm/src/credentials/azureCliCredentialOptions.js +4 -0
- package/dist-esm/src/credentials/azureCliCredentialOptions.js.map +1 -0
- package/dist-esm/src/credentials/azurePowerShellCredential.browser.js +20 -0
- package/dist-esm/src/credentials/azurePowerShellCredential.browser.js.map +1 -0
- package/dist-esm/src/credentials/azurePowerShellCredential.js +173 -0
- package/dist-esm/src/credentials/azurePowerShellCredential.js.map +1 -0
- package/dist-esm/src/credentials/azurePowerShellCredentialOptions.js +4 -0
- package/dist-esm/src/credentials/azurePowerShellCredentialOptions.js.map +1 -0
- package/dist-esm/src/credentials/chainedTokenCredential.js +37 -34
- package/dist-esm/src/credentials/chainedTokenCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientCertificateCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/clientCertificateCredential.js +9 -11
- package/dist-esm/src/credentials/clientCertificateCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientCertificateCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/clientSecretCredential.browser.js +87 -0
- package/dist-esm/src/credentials/clientSecretCredential.browser.js.map +1 -0
- package/dist-esm/src/credentials/clientSecretCredential.js +9 -11
- package/dist-esm/src/credentials/clientSecretCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientSecretCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/credentialPersistenceOptions.js +4 -0
- package/dist-esm/src/credentials/credentialPersistenceOptions.js.map +1 -0
- package/dist-esm/src/credentials/defaultAzureCredential.browser.js +1 -1
- package/dist-esm/src/credentials/defaultAzureCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/defaultAzureCredential.js +38 -19
- package/dist-esm/src/credentials/defaultAzureCredential.js.map +1 -1
- package/dist-esm/src/credentials/deviceCodeCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/deviceCodeCredential.js +13 -22
- package/dist-esm/src/credentials/deviceCodeCredential.js.map +1 -1
- package/dist-esm/src/credentials/deviceCodeCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/environmentCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/environmentCredential.js +47 -30
- package/dist-esm/src/credentials/environmentCredential.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js +14 -23
- package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredential.js +20 -26
- package/dist-esm/src/credentials/interactiveBrowserCredential.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/interactiveCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2017.js +36 -18
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2017.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js +61 -42
- package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/cloudShellMsi.js +33 -18
- package/dist-esm/src/credentials/managedIdentityCredential/cloudShellMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/constants.js +2 -1
- package/dist-esm/src/credentials/managedIdentityCredential/constants.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/fabricMsi.js +42 -23
- package/dist-esm/src/credentials/managedIdentityCredential/fabricMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js +108 -73
- package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/index.browser.js +3 -6
- package/dist-esm/src/credentials/managedIdentityCredential/index.browser.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/index.js +119 -124
- package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/models.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/tokenExchangeMsi.js +82 -0
- package/dist-esm/src/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -0
- package/dist-esm/src/credentials/managedIdentityCredential/utils.js +14 -8
- package/dist-esm/src/credentials/managedIdentityCredential/utils.js.map +1 -1
- package/dist-esm/src/credentials/onBehalfOfCredential.browser.js +17 -0
- package/dist-esm/src/credentials/onBehalfOfCredential.browser.js.map +1 -0
- package/dist-esm/src/credentials/onBehalfOfCredential.js +62 -0
- package/dist-esm/src/credentials/onBehalfOfCredential.js.map +1 -0
- package/dist-esm/src/credentials/onBehalfOfCredentialOptions.js +4 -0
- package/dist-esm/src/credentials/onBehalfOfCredentialOptions.js.map +1 -0
- package/dist-esm/src/credentials/usernamePasswordCredential.browser.js +87 -0
- package/dist-esm/src/credentials/usernamePasswordCredential.browser.js.map +1 -0
- package/dist-esm/src/credentials/usernamePasswordCredential.js +9 -33
- package/dist-esm/src/credentials/usernamePasswordCredential.js.map +1 -1
- package/dist-esm/src/credentials/usernamePasswordCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/visualStudioCodeCredential.browser.js +5 -0
- package/dist-esm/src/credentials/visualStudioCodeCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/visualStudioCodeCredential.js +70 -68
- package/dist-esm/src/credentials/visualStudioCodeCredential.js.map +1 -1
- package/dist-esm/src/credentials/visualStudioCodeCredentialPlugin.js +4 -0
- package/dist-esm/src/credentials/visualStudioCodeCredentialPlugin.js.map +1 -0
- package/dist-esm/src/index.js +6 -1
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/msal/browserFlows/browserCommon.js +30 -29
- package/dist-esm/src/msal/browserFlows/browserCommon.js.map +1 -1
- package/dist-esm/src/msal/browserFlows/msalAuthCode.js +103 -113
- package/dist-esm/src/msal/browserFlows/msalAuthCode.js.map +1 -1
- package/dist-esm/src/msal/credentials.js.map +1 -1
- package/dist-esm/src/msal/errors.js +1 -2
- package/dist-esm/src/msal/errors.js.map +1 -1
- package/dist-esm/src/msal/flows.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js +41 -0
- package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js.map +1 -0
- package/dist-esm/src/msal/nodeFlows/msalClientCertificate.js +64 -46
- package/dist-esm/src/msal/nodeFlows/msalClientCertificate.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalClientSecret.js +15 -16
- package/dist-esm/src/msal/nodeFlows/msalClientSecret.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalDeviceCode.js +20 -22
- package/dist-esm/src/msal/nodeFlows/msalDeviceCode.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalOnBehalfOf.js +56 -0
- package/dist-esm/src/msal/nodeFlows/msalOnBehalfOf.js.map +1 -0
- package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js +43 -32
- package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalUsernamePassword.js +15 -17
- package/dist-esm/src/msal/nodeFlows/msalUsernamePassword.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/nodeCommon.js +133 -110
- package/dist-esm/src/msal/nodeFlows/nodeCommon.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/tokenCachePersistenceOptions.js +4 -0
- package/dist-esm/src/msal/nodeFlows/tokenCachePersistenceOptions.js.map +1 -0
- package/dist-esm/src/msal/utils.js +31 -22
- package/dist-esm/src/msal/utils.js.map +1 -1
- package/dist-esm/src/plugins/consumer.browser.js +7 -0
- package/dist-esm/src/plugins/consumer.browser.js.map +1 -0
- package/dist-esm/src/plugins/consumer.js +44 -0
- package/dist-esm/src/plugins/consumer.js.map +1 -0
- package/dist-esm/src/{tokenCache/types.js → plugins/provider.js} +1 -1
- package/dist-esm/src/plugins/provider.js.map +1 -0
- package/dist-esm/src/regionalAuthority.js +115 -0
- package/dist-esm/src/regionalAuthority.js.map +1 -0
- package/dist-esm/src/util/logging.js +1 -1
- package/dist-esm/src/util/logging.js.map +1 -1
- package/dist-esm/src/util/processUtils.js +32 -0
- package/dist-esm/src/util/processUtils.js.map +1 -0
- package/dist-esm/src/util/scopeUtils.js +22 -0
- package/dist-esm/src/util/scopeUtils.js.map +1 -0
- package/dist-esm/src/util/tracing.js +23 -26
- package/dist-esm/src/util/tracing.js.map +1 -1
- package/dist-esm/src/util/validateMultiTenant.js +24 -0
- package/dist-esm/src/util/validateMultiTenant.js.map +1 -0
- package/package.json +43 -41
- package/types/identity.d.ts +500 -131
- package/dist-esm/src/tokenCache/TokenCachePersistence.browser.js +0 -23
- package/dist-esm/src/tokenCache/TokenCachePersistence.browser.js.map +0 -1
- package/dist-esm/src/tokenCache/TokenCachePersistence.js +0 -51
- package/dist-esm/src/tokenCache/TokenCachePersistence.js.map +0 -1
- package/dist-esm/src/tokenCache/nodeVersion.js +0 -10
- package/dist-esm/src/tokenCache/nodeVersion.js.map +0 -1
- package/dist-esm/src/tokenCache/persistencePlatforms.js +0 -150
- package/dist-esm/src/tokenCache/persistencePlatforms.js.map +0 -1
- package/dist-esm/src/tokenCache/types.js.map +0 -1
- package/dist-esm/src/util/authHostEnv.js +0 -13
- package/dist-esm/src/util/authHostEnv.js.map +0 -1
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
|
-
import { __awaiter } from "tslib";
|
|
4
3
|
import { DefaultTenantId } from "../../constants";
|
|
5
4
|
import { resolveTenantId } from "../../util/resolveTenantId";
|
|
6
|
-
import {
|
|
5
|
+
import { getAuthority, getKnownAuthorities, MsalBaseUtilities } from "../utils";
|
|
7
6
|
import { AuthenticationRequiredError } from "../errors";
|
|
8
7
|
import { CredentialUnavailableError } from "../../client/errors";
|
|
8
|
+
import { processMultiTenantRequest } from "../../util/validateMultiTenant";
|
|
9
9
|
/**
|
|
10
10
|
* Generates a MSAL configuration that generally works for browsers
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
13
|
export function defaultBrowserMsalConfig(options) {
|
|
14
14
|
const tenantId = options.tenantId || DefaultTenantId;
|
|
15
|
-
const
|
|
15
|
+
const authority = getAuthority(tenantId, options.authorityHost);
|
|
16
16
|
return {
|
|
17
17
|
auth: {
|
|
18
18
|
clientId: options.clientId,
|
|
19
|
-
authority
|
|
20
|
-
knownAuthorities: getKnownAuthorities(tenantId,
|
|
19
|
+
authority,
|
|
20
|
+
knownAuthorities: getKnownAuthorities(tenantId, authority),
|
|
21
21
|
// If the users picked redirect as their login style,
|
|
22
22
|
// but they didn't provide a redirectUri,
|
|
23
23
|
// we can try to use the current page we're in as a default value.
|
|
@@ -44,6 +44,8 @@ export class MsalBrowser extends MsalBaseUtilities {
|
|
|
44
44
|
}
|
|
45
45
|
this.clientId = options.clientId;
|
|
46
46
|
this.tenantId = resolveTenantId(this.logger, options.tenantId, options.clientId);
|
|
47
|
+
this.allowMultiTenantAuthentication = options === null || options === void 0 ? void 0 : options.allowMultiTenantAuthentication;
|
|
48
|
+
this.authorityHost = options.authorityHost;
|
|
47
49
|
this.msalConfig = defaultBrowserMsalConfig(options);
|
|
48
50
|
this.disableAutomaticAuthentication = options.disableAutomaticAuthentication;
|
|
49
51
|
if (options.authenticationRecord) {
|
|
@@ -53,40 +55,39 @@ export class MsalBrowser extends MsalBaseUtilities {
|
|
|
53
55
|
/**
|
|
54
56
|
* In the browsers we don't need to init()
|
|
55
57
|
*/
|
|
56
|
-
init() {
|
|
57
|
-
|
|
58
|
-
// Nothing to do here.
|
|
59
|
-
});
|
|
58
|
+
async init() {
|
|
59
|
+
// Nothing to do here.
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* Clears MSAL's cache.
|
|
63
63
|
*/
|
|
64
|
-
logout() {
|
|
64
|
+
async logout() {
|
|
65
65
|
var _a;
|
|
66
|
-
|
|
67
|
-
(_a = this.app) === null || _a === void 0 ? void 0 : _a.logout();
|
|
68
|
-
});
|
|
66
|
+
(_a = this.app) === null || _a === void 0 ? void 0 : _a.logout();
|
|
69
67
|
}
|
|
70
68
|
/**
|
|
71
69
|
* Attempts to retrieve an authenticated token from MSAL.
|
|
72
70
|
*/
|
|
73
|
-
getToken(scopes, options) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
async getToken(scopes, options = {}) {
|
|
72
|
+
const tenantId = processMultiTenantRequest(this.tenantId, this.allowMultiTenantAuthentication, options) ||
|
|
73
|
+
this.tenantId;
|
|
74
|
+
if (!options.authority) {
|
|
75
|
+
options.authority = getAuthority(tenantId, this.authorityHost);
|
|
76
|
+
}
|
|
77
|
+
// We ensure that redirection is handled at this point.
|
|
78
|
+
await this.handleRedirect();
|
|
79
|
+
if (!(await this.getActiveAccount()) && !this.disableAutomaticAuthentication) {
|
|
80
|
+
await this.login(scopes);
|
|
81
|
+
}
|
|
82
|
+
return this.getTokenSilent(scopes).catch((err) => {
|
|
83
|
+
if (err.name !== "AuthenticationRequiredError") {
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
if (options === null || options === void 0 ? void 0 : options.disableAutomaticAuthentication) {
|
|
87
|
+
throw new AuthenticationRequiredError(scopes, options, "Automatic authentication has been disabled. You may call the authentication() method.");
|
|
79
88
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
throw err;
|
|
83
|
-
}
|
|
84
|
-
if (options === null || options === void 0 ? void 0 : options.disableAutomaticAuthentication) {
|
|
85
|
-
throw new AuthenticationRequiredError(scopes, options, "Automatic authentication has been disabled. You may call the authentication() method.");
|
|
86
|
-
}
|
|
87
|
-
this.logger.info(`Silent authentication failed, falling back to interactive method ${this.loginStyle}`);
|
|
88
|
-
return this.doGetToken(scopes);
|
|
89
|
-
});
|
|
89
|
+
this.logger.info(`Silent authentication failed, falling back to interactive method ${this.loginStyle}`);
|
|
90
|
+
return this.doGetToken(scopes);
|
|
90
91
|
});
|
|
91
92
|
}
|
|
92
93
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browserCommon.js","sourceRoot":"","sources":["../../../../src/msal/browserFlows/browserCommon.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC
|
|
1
|
+
{"version":3,"file":"browserCommon.js","sourceRoot":"","sources":["../../../../src/msal/browserFlows/browserCommon.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAMlC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAIhF,OAAO,EAA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,aAAP,OAAO,uBAAP,OAAO,CAAE,8BAA8B,EAAE;gBAC3C,MAAM,IAAI,2BAA2B,CACnC,MAAM,EACN,OAAO,EACP,uFAAuF,CACxF,CAAC;aACH;YACD,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,oEAAoE,IAAI,CAAC,UAAU,EAAE,CACtF,CAAC;YACF,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as msalBrowser from \"@azure/msal-browser\";\n\nimport { AccessToken } from \"@azure/core-auth\";\n\nimport { DefaultTenantId } from \"../../constants\";\nimport { resolveTenantId } from \"../../util/resolveTenantId\";\nimport { BrowserLoginStyle } from \"../../credentials/interactiveBrowserCredentialOptions\";\nimport { getAuthority, getKnownAuthorities, MsalBaseUtilities } from \"../utils\";\nimport { MsalFlow, MsalFlowOptions } from \"../flows\";\nimport { AuthenticationRecord } from \"../types\";\nimport { CredentialFlowGetTokenOptions } from \"../credentials\";\nimport { AuthenticationRequiredError } from \"../errors\";\nimport { CredentialUnavailableError } from \"../../client/errors\";\nimport { processMultiTenantRequest } from \"../../util/validateMultiTenant\";\n\n/**\n * Union of the constructor parameters that all MSAL flow types take.\n * Some properties might not be used by some flow types.\n */\nexport interface MsalBrowserFlowOptions extends MsalFlowOptions {\n redirectUri?: string;\n loginStyle: BrowserLoginStyle;\n allowMultiTenantAuthentication?: boolean;\n loginHint?: string;\n}\n\n/**\n * The common methods we use to work with the MSAL browser flows.\n * @internal\n */\nexport interface MsalBrowserFlow extends MsalFlow {\n login(scopes?: string[]): Promise<AuthenticationRecord | undefined>;\n handleRedirect(): Promise<AuthenticationRecord | undefined>;\n}\n\n/**\n * Generates a MSAL configuration that generally works for browsers\n * @internal\n */\nexport function defaultBrowserMsalConfig(\n options: MsalBrowserFlowOptions\n): msalBrowser.Configuration {\n const tenantId = options.tenantId || DefaultTenantId;\n const authority = getAuthority(tenantId, options.authorityHost);\n return {\n auth: {\n clientId: options.clientId!,\n authority,\n knownAuthorities: getKnownAuthorities(tenantId, authority),\n // If the users picked redirect as their login style,\n // but they didn't provide a redirectUri,\n // we can try to use the current page we're in as a default value.\n redirectUri: options.redirectUri || self.location.origin\n }\n };\n}\n\n/**\n * MSAL partial base client for the browsers.\n *\n * It completes the input configuration with some default values.\n * It also provides with utility protected methods that can be used from any of the clients,\n * which includes handlers for successful responses and errors.\n *\n * @internal\n */\nexport abstract class MsalBrowser extends MsalBaseUtilities implements MsalBrowserFlow {\n protected loginStyle: BrowserLoginStyle;\n protected clientId: string;\n protected tenantId: string;\n protected allowMultiTenantAuthentication?: boolean;\n protected authorityHost?: string;\n protected account: AuthenticationRecord | undefined;\n protected msalConfig: msalBrowser.Configuration;\n protected disableAutomaticAuthentication?: boolean;\n protected app?: msalBrowser.PublicClientApplication;\n\n constructor(options: MsalBrowserFlowOptions) {\n super(options);\n this.logger = options.logger;\n this.loginStyle = options.loginStyle;\n if (!options.clientId) {\n throw new CredentialUnavailableError(\"A client ID is required in browsers\");\n }\n this.clientId = options.clientId;\n this.tenantId = resolveTenantId(this.logger, options.tenantId, options.clientId);\n this.allowMultiTenantAuthentication = options?.allowMultiTenantAuthentication;\n this.authorityHost = options.authorityHost;\n this.msalConfig = defaultBrowserMsalConfig(options);\n this.disableAutomaticAuthentication = options.disableAutomaticAuthentication;\n\n if (options.authenticationRecord) {\n this.account = {\n ...options.authenticationRecord,\n tenantId: this.tenantId\n };\n }\n }\n\n /**\n * In the browsers we don't need to init()\n */\n async init(): Promise<void> {\n // Nothing to do here.\n }\n\n /**\n * Attempts to handle a redirection request the least amount of times possible.\n */\n public abstract handleRedirect(): Promise<AuthenticationRecord | undefined>;\n\n /**\n * Clears MSAL's cache.\n */\n async logout(): Promise<void> {\n this.app?.logout();\n }\n\n /**\n * Uses MSAL to retrieve the active account.\n */\n public abstract getActiveAccount(): Promise<AuthenticationRecord | undefined>;\n\n /**\n * Uses MSAL to trigger a redirect or a popup login.\n */\n public abstract login(scopes?: string | string[]): Promise<AuthenticationRecord | undefined>;\n\n /**\n * Attempts to retrieve a token from cache.\n */\n public abstract getTokenSilent(scopes: string[]): Promise<AccessToken>;\n\n /**\n * Attempts to retrieve the token in the browser.\n */\n protected abstract doGetToken(scopes: string[]): Promise<AccessToken>;\n\n /**\n * Attempts to retrieve an authenticated token from MSAL.\n */\n public async getToken(\n scopes: string[],\n options: CredentialFlowGetTokenOptions = {}\n ): Promise<AccessToken> {\n const tenantId =\n processMultiTenantRequest(this.tenantId, this.allowMultiTenantAuthentication, options) ||\n this.tenantId;\n\n if (!options.authority) {\n options.authority = getAuthority(tenantId, this.authorityHost);\n }\n\n // We ensure that redirection is handled at this point.\n await this.handleRedirect();\n\n if (!(await this.getActiveAccount()) && !this.disableAutomaticAuthentication) {\n await this.login(scopes);\n }\n return this.getTokenSilent(scopes).catch((err) => {\n if (err.name !== \"AuthenticationRequiredError\") {\n throw err;\n }\n if (options?.disableAutomaticAuthentication) {\n throw new AuthenticationRequiredError(\n scopes,\n options,\n \"Automatic authentication has been disabled. You may call the authentication() method.\"\n );\n }\n this.logger.info(\n `Silent authentication failed, falling back to interactive method ${this.loginStyle}`\n );\n return this.doGetToken(scopes);\n });\n }\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
|
-
import { __awaiter } from "tslib";
|
|
4
3
|
import * as msalBrowser from "@azure/msal-browser";
|
|
5
4
|
import { MsalBrowser } from "./browserCommon";
|
|
6
5
|
import { defaultLoggerCallback, msalToPublic, publicToMsal } from "../utils";
|
|
@@ -21,13 +20,14 @@ export class MSALAuthCode extends MsalBrowser {
|
|
|
21
20
|
*/
|
|
22
21
|
constructor(options) {
|
|
23
22
|
super(options);
|
|
23
|
+
this.loginHint = options.loginHint;
|
|
24
24
|
this.msalConfig.cache = {
|
|
25
25
|
cacheLocation: "sessionStorage",
|
|
26
26
|
storeAuthStateInCookie: true // Set to true to improve the experience on IE11 and Edge.
|
|
27
27
|
};
|
|
28
28
|
this.msalConfig.system = {
|
|
29
29
|
loggerOptions: {
|
|
30
|
-
loggerCallback: defaultLoggerCallback(this.logger)
|
|
30
|
+
loggerCallback: defaultLoggerCallback(this.logger, "Browser")
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
// Preparing the MSAL application.
|
|
@@ -41,144 +41,134 @@ export class MSALAuthCode extends MsalBrowser {
|
|
|
41
41
|
* If no result was received, tries to load the account from the cache.
|
|
42
42
|
* @param result - Result object received from MSAL.
|
|
43
43
|
*/
|
|
44
|
-
handleBrowserResult(result) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this.logger.info(`More than one account was found authenticated for this Client ID and Tenant ID.
|
|
44
|
+
async handleBrowserResult(result) {
|
|
45
|
+
try {
|
|
46
|
+
if (result && result.account) {
|
|
47
|
+
this.logger.info(`MSAL Browser V2 authentication successful.`);
|
|
48
|
+
this.app.setActiveAccount(result.account);
|
|
49
|
+
return msalToPublic(this.clientId, result.account);
|
|
50
|
+
}
|
|
51
|
+
// If by this point we happen to have an active account, we should stop trying to parse this.
|
|
52
|
+
const activeAccount = await this.app.getActiveAccount();
|
|
53
|
+
if (activeAccount) {
|
|
54
|
+
return msalToPublic(this.clientId, activeAccount);
|
|
55
|
+
}
|
|
56
|
+
// If we don't have an active account, we try to activate it from all the already loaded accounts.
|
|
57
|
+
const accounts = this.app.getAllAccounts();
|
|
58
|
+
if (accounts.length > 1) {
|
|
59
|
+
// If there's more than one account in memory, we force the user to authenticate again.
|
|
60
|
+
// At this point we can't identify which account should this credential work with,
|
|
61
|
+
// since at this point the user won't have provided enough information.
|
|
62
|
+
// We log a message in case that helps.
|
|
63
|
+
this.logger.info(`More than one account was found authenticated for this Client ID and Tenant ID.
|
|
65
64
|
However, no "authenticationRecord" has been provided for this credential,
|
|
66
65
|
therefore we're unable to pick between these accounts.
|
|
67
66
|
A new login attempt will be requested, to ensure the correct account is picked.
|
|
68
67
|
To work with multiple accounts for the same Client ID and Tenant ID, please provide an "authenticationRecord" when initializing "InteractiveBrowserCredential".`);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
// If there's only one account for this MSAL object, we can safely activate it.
|
|
78
|
-
if (accounts.length === 1) {
|
|
79
|
-
const account = accounts[0];
|
|
80
|
-
this.app.setActiveAccount(account);
|
|
81
|
-
return msalToPublic(this.clientId, account);
|
|
82
|
-
}
|
|
83
|
-
this.logger.info(`No accounts were found through MSAL.`);
|
|
68
|
+
// To safely trigger a new login, we're also ensuring the local cache is cleared up for this MSAL object.
|
|
69
|
+
// However, we want to avoid kicking the user out of their authentication on the Azure side.
|
|
70
|
+
// We do this by calling to logout while specifying a `onRedirectNavigate` that returns false.
|
|
71
|
+
await this.app.logout({
|
|
72
|
+
onRedirectNavigate: () => false
|
|
73
|
+
});
|
|
74
|
+
return;
|
|
84
75
|
}
|
|
85
|
-
|
|
86
|
-
|
|
76
|
+
// If there's only one account for this MSAL object, we can safely activate it.
|
|
77
|
+
if (accounts.length === 1) {
|
|
78
|
+
const account = accounts[0];
|
|
79
|
+
this.app.setActiveAccount(account);
|
|
80
|
+
return msalToPublic(this.clientId, account);
|
|
87
81
|
}
|
|
88
|
-
|
|
89
|
-
}
|
|
82
|
+
this.logger.info(`No accounts were found through MSAL.`);
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
this.logger.info(`Failed to acquire token through MSAL. ${e.message}`);
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
90
88
|
}
|
|
91
89
|
/**
|
|
92
90
|
* Uses MSAL to handle the redirect.
|
|
93
91
|
*/
|
|
94
|
-
handleRedirect() {
|
|
95
|
-
return
|
|
96
|
-
return this.handleBrowserResult((yield this.app.handleRedirectPromise(redirectHash)) || undefined);
|
|
97
|
-
});
|
|
92
|
+
async handleRedirect() {
|
|
93
|
+
return this.handleBrowserResult((await this.app.handleRedirectPromise(redirectHash)) || undefined);
|
|
98
94
|
}
|
|
99
95
|
/**
|
|
100
96
|
* Uses MSAL to trigger a redirect or a popup login.
|
|
101
97
|
*/
|
|
102
|
-
login(scopes = []) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
case "popup":
|
|
114
|
-
return this.handleBrowserResult(yield this.app.loginPopup(loginRequest));
|
|
98
|
+
async login(scopes = []) {
|
|
99
|
+
const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];
|
|
100
|
+
const loginRequest = {
|
|
101
|
+
scopes: arrayScopes,
|
|
102
|
+
loginHint: this.loginHint
|
|
103
|
+
};
|
|
104
|
+
switch (this.loginStyle) {
|
|
105
|
+
case "redirect": {
|
|
106
|
+
await this.app.loginRedirect(loginRequest);
|
|
107
|
+
return;
|
|
115
108
|
}
|
|
116
|
-
|
|
109
|
+
case "popup":
|
|
110
|
+
return this.handleBrowserResult(await this.app.loginPopup(loginRequest));
|
|
111
|
+
}
|
|
117
112
|
}
|
|
118
113
|
/**
|
|
119
114
|
* Uses MSAL to retrieve the active account.
|
|
120
115
|
*/
|
|
121
|
-
getActiveAccount() {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return msalToPublic(this.clientId, account);
|
|
128
|
-
});
|
|
116
|
+
async getActiveAccount() {
|
|
117
|
+
const account = this.app.getActiveAccount();
|
|
118
|
+
if (!account) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
return msalToPublic(this.clientId, account);
|
|
129
122
|
}
|
|
130
123
|
/**
|
|
131
124
|
* Attempts to retrieve a token from cache.
|
|
132
125
|
*/
|
|
133
|
-
getTokenSilent(scopes, options) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
});
|
|
126
|
+
async getTokenSilent(scopes, options) {
|
|
127
|
+
const account = await this.getActiveAccount();
|
|
128
|
+
if (!account) {
|
|
129
|
+
throw new AuthenticationRequiredError(scopes, options);
|
|
130
|
+
}
|
|
131
|
+
const parameters = {
|
|
132
|
+
authority: (options === null || options === void 0 ? void 0 : options.authority) || this.msalConfig.auth.authority,
|
|
133
|
+
correlationId: options === null || options === void 0 ? void 0 : options.correlationId,
|
|
134
|
+
account: publicToMsal(account),
|
|
135
|
+
forceRefresh: false,
|
|
136
|
+
scopes
|
|
137
|
+
};
|
|
138
|
+
try {
|
|
139
|
+
this.logger.info("Attempting to acquire token silently");
|
|
140
|
+
const response = await this.app.acquireTokenSilent(parameters);
|
|
141
|
+
return this.handleResult(scopes, this.clientId, response);
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
throw this.handleError(scopes, err, options);
|
|
145
|
+
}
|
|
155
146
|
}
|
|
156
147
|
/**
|
|
157
148
|
* Attempts to retrieve the token in the browser.
|
|
158
149
|
*/
|
|
159
|
-
doGetToken(scopes, options) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
});
|
|
150
|
+
async doGetToken(scopes, options) {
|
|
151
|
+
const account = await this.getActiveAccount();
|
|
152
|
+
if (!account) {
|
|
153
|
+
throw new AuthenticationRequiredError(scopes, options);
|
|
154
|
+
}
|
|
155
|
+
const parameters = {
|
|
156
|
+
authority: (options === null || options === void 0 ? void 0 : options.authority) || this.msalConfig.auth.authority,
|
|
157
|
+
correlationId: options === null || options === void 0 ? void 0 : options.correlationId,
|
|
158
|
+
account: publicToMsal(account),
|
|
159
|
+
loginHint: this.loginHint,
|
|
160
|
+
scopes
|
|
161
|
+
};
|
|
162
|
+
switch (this.loginStyle) {
|
|
163
|
+
case "redirect":
|
|
164
|
+
// This will go out of the page.
|
|
165
|
+
// Once the InteractiveBrowserCredential is initialized again,
|
|
166
|
+
// we'll load the MSAL account in the constructor.
|
|
167
|
+
await this.app.acquireTokenRedirect(parameters);
|
|
168
|
+
return { token: "", expiresOnTimestamp: 0 };
|
|
169
|
+
case "popup":
|
|
170
|
+
return this.handleResult(scopes, this.clientId, await this.app.acquireTokenPopup(parameters));
|
|
171
|
+
}
|
|
182
172
|
}
|
|
183
173
|
}
|
|
184
174
|
//# sourceMappingURL=msalAuthCode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"msalAuthCode.js","sourceRoot":"","sources":["../../../../src/msal/browserFlows/msalAuthCode.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAA0B,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEtE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AA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nimport * as msalBrowser from \"@azure/msal-browser\";\nimport { MsalBrowserFlowOptions, MsalBrowser } from \"./browserCommon\";\nimport { AccessToken } from \"@azure/core-http\";\nimport { defaultLoggerCallback, msalToPublic, publicToMsal } from \"../utils\";\nimport { AuthenticationRecord } from \"../types\";\nimport { AuthenticationRequiredError } from \"../errors\";\nimport { CredentialFlowGetTokenOptions } from \"../credentials\";\n\n// We keep a copy of the redirect hash.\nconst redirectHash = self.location.hash;\n\n/**\n * Uses MSAL Browser 2.X for browser authentication,\n * which uses the [Auth Code Flow](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow).\n * @internal\n */\nexport class MSALAuthCode extends MsalBrowser {\n protected app: msalBrowser.PublicClientApplication;\n\n /**\n * Sets up an MSAL object based on the given parameters.\n * MSAL with Auth Code allows sending a previously obtained `authenticationRecord` through the optional parameters,\n * which is set to be the active account.\n * @param options - Parameters necessary and otherwise used to create the MSAL object.\n */\n constructor(options: MsalBrowserFlowOptions) {\n super(options);\n\n this.msalConfig.cache = {\n cacheLocation: \"sessionStorage\",\n storeAuthStateInCookie: true // Set to true to improve the experience on IE11 and Edge.\n };\n this.msalConfig.system = {\n loggerOptions: {\n loggerCallback: defaultLoggerCallback(this.logger)\n }\n };\n\n // Preparing the MSAL application.\n this.app = new msalBrowser.PublicClientApplication(\n this.msalConfig as msalBrowser.Configuration\n );\n if (this.account) {\n this.app.setActiveAccount(publicToMsal(this.account));\n }\n }\n\n /**\n * Loads the account based on the result of the authentication.\n * If no result was received, tries to load the account from the cache.\n * @param result - Result object received from MSAL.\n */\n private async handleBrowserResult(\n result?: msalBrowser.AuthenticationResult\n ): Promise<AuthenticationRecord | undefined> {\n try {\n if (result && result.account) {\n this.logger.info(`MSAL Browser V2 authentication successful.`);\n this.app.setActiveAccount(result.account);\n return msalToPublic(this.clientId, result.account);\n }\n\n // If by this point we happen to have an active account, we should stop trying to parse this.\n const activeAccount = await this.app!.getActiveAccount();\n if (activeAccount) {\n return msalToPublic(this.clientId, activeAccount);\n }\n\n // If we don't have an active account, we try to activate it from all the already loaded accounts.\n const accounts = this.app.getAllAccounts();\n if (accounts.length > 1) {\n // If there's more than one account in memory, we force the user to authenticate again.\n // At this point we can't identify which account should this credential work with,\n // since at this point the user won't have provided enough information.\n // We log a message in case that helps.\n this.logger.info(\n `More than one account was found authenticated for this Client ID and Tenant ID.\nHowever, no \"authenticationRecord\" has been provided for this credential,\ntherefore we're unable to pick between these accounts.\nA new login attempt will be requested, to ensure the correct account is picked.\nTo work with multiple accounts for the same Client ID and Tenant ID, please provide an \"authenticationRecord\" when initializing \"InteractiveBrowserCredential\".`\n );\n // To safely trigger a new login, we're also ensuring the local cache is cleared up for this MSAL object.\n // However, we want to avoid kicking the user out of their authentication on the Azure side.\n // We do this by calling to logout while specifying a `onRedirectNavigate` that returns false.\n await this.app.logout({\n onRedirectNavigate: () => false\n });\n return;\n }\n\n // If there's only one account for this MSAL object, we can safely activate it.\n if (accounts.length === 1) {\n const account = accounts[0];\n this.app.setActiveAccount(account);\n return msalToPublic(this.clientId, account);\n }\n\n this.logger.info(`No accounts were found through MSAL.`);\n } catch (e) {\n this.logger.info(`Failed to acquire token through MSAL. ${e.message}`);\n }\n return;\n }\n\n /**\n * Uses MSAL to handle the redirect.\n */\n public async handleRedirect(): Promise<AuthenticationRecord | undefined> {\n return this.handleBrowserResult(\n (await this.app.handleRedirectPromise(redirectHash)) || undefined\n );\n }\n\n /**\n * Uses MSAL to trigger a redirect or a popup login.\n */\n public async login(scopes: string | string[] = []): Promise<AuthenticationRecord | undefined> {\n const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];\n const loginRequest = {\n scopes: arrayScopes\n };\n switch (this.loginStyle) {\n case \"redirect\": {\n await this.app.loginRedirect(loginRequest);\n return;\n }\n case \"popup\":\n return this.handleBrowserResult(await this.app.loginPopup(loginRequest));\n }\n }\n\n /**\n * Uses MSAL to retrieve the active account.\n */\n public async getActiveAccount(): Promise<AuthenticationRecord | undefined> {\n const account = this.app.getActiveAccount();\n if (!account) {\n return;\n }\n return msalToPublic(this.clientId, account);\n }\n\n /**\n * Attempts to retrieve a token from cache.\n */\n public async getTokenSilent(\n scopes: string[],\n options?: CredentialFlowGetTokenOptions\n ): Promise<AccessToken> {\n const account = await this.getActiveAccount();\n if (!account) {\n throw new AuthenticationRequiredError(scopes, options);\n }\n\n const parameters: msalBrowser.SilentRequest = {\n authority: this.msalConfig.auth.authority!,\n correlationId: options?.correlationId,\n account: publicToMsal(account),\n forceRefresh: false,\n scopes\n };\n\n try {\n this.logger.info(\"Attempting to acquire token silently\");\n const response = await this.app.acquireTokenSilent(parameters);\n return this.handleResult(scopes, this.clientId, response);\n } catch (err) {\n throw this.handleError(scopes, err, options);\n }\n }\n\n /**\n * Attempts to retrieve the token in the browser.\n */\n protected async doGetToken(\n scopes: string[],\n options?: CredentialFlowGetTokenOptions\n ): Promise<AccessToken> {\n const account = await this.getActiveAccount();\n if (!account) {\n throw new AuthenticationRequiredError(scopes, options);\n }\n\n const parameters: msalBrowser.RedirectRequest = {\n authority: this.msalConfig.auth.authority!,\n correlationId: options?.correlationId,\n account: publicToMsal(account),\n scopes\n };\n\n switch (this.loginStyle) {\n case \"redirect\":\n // This will go out of the page.\n // Once the InteractiveBrowserCredential is initialized again,\n // we'll load the MSAL account in the constructor.\n await this.app.acquireTokenRedirect(parameters);\n return { token: \"\", expiresOnTimestamp: 0 };\n case \"popup\":\n return this.handleResult(\n scopes,\n this.clientId,\n await this.app.acquireTokenPopup(parameters)\n );\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"msalAuthCode.js","sourceRoot":"","sources":["../../../../src/msal/browserFlows/msalAuthCode.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAC;AAInD,OAAO,EAA0B,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,YA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kBAAkB,EAAE,CAAC,EAAE,CAAC;YAC9C,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,YAAY,CACtB,MAAM,EACN,IAAI,CAAC,QAAQ,EACb,MAAM,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAC7C,CAAC;SACL;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as msalBrowser from \"@azure/msal-browser\";\n\nimport { AccessToken } from \"@azure/core-auth\";\n\nimport { MsalBrowserFlowOptions, MsalBrowser } from \"./browserCommon\";\nimport { defaultLoggerCallback, msalToPublic, publicToMsal } from \"../utils\";\nimport { AuthenticationRecord } from \"../types\";\nimport { AuthenticationRequiredError } from \"../errors\";\nimport { CredentialFlowGetTokenOptions } from \"../credentials\";\n\n// We keep a copy of the redirect hash.\nconst redirectHash = self.location.hash;\n\n/**\n * Uses MSAL Browser 2.X for browser authentication,\n * which uses the [Auth Code Flow](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow).\n * @internal\n */\nexport class MSALAuthCode extends MsalBrowser {\n protected app: msalBrowser.PublicClientApplication;\n private loginHint?: string;\n\n /**\n * Sets up an MSAL object based on the given parameters.\n * MSAL with Auth Code allows sending a previously obtained `authenticationRecord` through the optional parameters,\n * which is set to be the active account.\n * @param options - Parameters necessary and otherwise used to create the MSAL object.\n */\n constructor(options: MsalBrowserFlowOptions) {\n super(options);\n this.loginHint = options.loginHint;\n\n this.msalConfig.cache = {\n cacheLocation: \"sessionStorage\",\n storeAuthStateInCookie: true // Set to true to improve the experience on IE11 and Edge.\n };\n this.msalConfig.system = {\n loggerOptions: {\n loggerCallback: defaultLoggerCallback(this.logger, \"Browser\")\n }\n };\n\n // Preparing the MSAL application.\n this.app = new msalBrowser.PublicClientApplication(\n this.msalConfig as msalBrowser.Configuration\n );\n if (this.account) {\n this.app.setActiveAccount(publicToMsal(this.account));\n }\n }\n\n /**\n * Loads the account based on the result of the authentication.\n * If no result was received, tries to load the account from the cache.\n * @param result - Result object received from MSAL.\n */\n private async handleBrowserResult(\n result?: msalBrowser.AuthenticationResult\n ): Promise<AuthenticationRecord | undefined> {\n try {\n if (result && result.account) {\n this.logger.info(`MSAL Browser V2 authentication successful.`);\n this.app.setActiveAccount(result.account);\n return msalToPublic(this.clientId, result.account);\n }\n\n // If by this point we happen to have an active account, we should stop trying to parse this.\n const activeAccount = await this.app!.getActiveAccount();\n if (activeAccount) {\n return msalToPublic(this.clientId, activeAccount);\n }\n\n // If we don't have an active account, we try to activate it from all the already loaded accounts.\n const accounts = this.app.getAllAccounts();\n if (accounts.length > 1) {\n // If there's more than one account in memory, we force the user to authenticate again.\n // At this point we can't identify which account should this credential work with,\n // since at this point the user won't have provided enough information.\n // We log a message in case that helps.\n this.logger.info(\n `More than one account was found authenticated for this Client ID and Tenant ID.\nHowever, no \"authenticationRecord\" has been provided for this credential,\ntherefore we're unable to pick between these accounts.\nA new login attempt will be requested, to ensure the correct account is picked.\nTo work with multiple accounts for the same Client ID and Tenant ID, please provide an \"authenticationRecord\" when initializing \"InteractiveBrowserCredential\".`\n );\n // To safely trigger a new login, we're also ensuring the local cache is cleared up for this MSAL object.\n // However, we want to avoid kicking the user out of their authentication on the Azure side.\n // We do this by calling to logout while specifying a `onRedirectNavigate` that returns false.\n await this.app.logout({\n onRedirectNavigate: () => false\n });\n return;\n }\n\n // If there's only one account for this MSAL object, we can safely activate it.\n if (accounts.length === 1) {\n const account = accounts[0];\n this.app.setActiveAccount(account);\n return msalToPublic(this.clientId, account);\n }\n\n this.logger.info(`No accounts were found through MSAL.`);\n } catch (e) {\n this.logger.info(`Failed to acquire token through MSAL. ${e.message}`);\n }\n return;\n }\n\n /**\n * Uses MSAL to handle the redirect.\n */\n public async handleRedirect(): Promise<AuthenticationRecord | undefined> {\n return this.handleBrowserResult(\n (await this.app.handleRedirectPromise(redirectHash)) || undefined\n );\n }\n\n /**\n * Uses MSAL to trigger a redirect or a popup login.\n */\n public async login(scopes: string | string[] = []): Promise<AuthenticationRecord | undefined> {\n const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];\n const loginRequest: msalBrowser.RedirectRequest = {\n scopes: arrayScopes,\n loginHint: this.loginHint\n };\n switch (this.loginStyle) {\n case \"redirect\": {\n await this.app.loginRedirect(loginRequest);\n return;\n }\n case \"popup\":\n return this.handleBrowserResult(await this.app.loginPopup(loginRequest));\n }\n }\n\n /**\n * Uses MSAL to retrieve the active account.\n */\n public async getActiveAccount(): Promise<AuthenticationRecord | undefined> {\n const account = this.app.getActiveAccount();\n if (!account) {\n return;\n }\n return msalToPublic(this.clientId, account);\n }\n\n /**\n * Attempts to retrieve a token from cache.\n */\n public async getTokenSilent(\n scopes: string[],\n options?: CredentialFlowGetTokenOptions\n ): Promise<AccessToken> {\n const account = await this.getActiveAccount();\n if (!account) {\n throw new AuthenticationRequiredError(scopes, options);\n }\n\n const parameters: msalBrowser.SilentRequest = {\n authority: options?.authority || this.msalConfig.auth.authority!,\n correlationId: options?.correlationId,\n account: publicToMsal(account),\n forceRefresh: false,\n scopes\n };\n\n try {\n this.logger.info(\"Attempting to acquire token silently\");\n const response = await this.app.acquireTokenSilent(parameters);\n return this.handleResult(scopes, this.clientId, response);\n } catch (err) {\n throw this.handleError(scopes, err, options);\n }\n }\n\n /**\n * Attempts to retrieve the token in the browser.\n */\n protected async doGetToken(\n scopes: string[],\n options?: CredentialFlowGetTokenOptions\n ): Promise<AccessToken> {\n const account = await this.getActiveAccount();\n if (!account) {\n throw new AuthenticationRequiredError(scopes, options);\n }\n\n const parameters: msalBrowser.RedirectRequest = {\n authority: options?.authority || this.msalConfig.auth.authority!,\n correlationId: options?.correlationId,\n account: publicToMsal(account),\n loginHint: this.loginHint,\n scopes\n };\n\n switch (this.loginStyle) {\n case \"redirect\":\n // This will go out of the page.\n // Once the InteractiveBrowserCredential is initialized again,\n // we'll load the MSAL account in the constructor.\n await this.app.acquireTokenRedirect(parameters);\n return { token: \"\", expiresOnTimestamp: 0 };\n case \"popup\":\n return this.handleResult(\n scopes,\n this.clientId,\n await this.app.acquireTokenPopup(parameters)\n );\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../../src/msal/credentials.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AccessToken, GetTokenOptions } from \"@azure/core-
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../../src/msal/credentials.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AccessToken, GetTokenOptions } from \"@azure/core-auth\";\n\nimport { AuthenticationRecord } from \"./types\";\n\n/**\n * The MSAL clients `getToken` requests can receive a `correlationId` and `disableAutomaticAuthentication`.\n * (which is used to prevent `getToken` from triggering the manual authentication if `getTokenSilent` fails).\n * @internal\n */\nexport interface CredentialFlowGetTokenOptions extends GetTokenOptions {\n /**\n * Unique identifier useful to track outgoing requests.\n */\n correlationId?: string;\n /**\n * Makes getToken throw if a manual authentication is necessary.\n */\n disableAutomaticAuthentication?: boolean;\n /**\n * Authority, to overwrite the default one, if necessary.\n */\n authority?: string;\n}\n\n/**\n * Simplified representation of the internal authentication flow.\n * @internal\n */\nexport interface CredentialFlow {\n /**\n * Clears the MSAL cache.\n */\n logout(): Promise<void>;\n /**\n * Tries to load the active account, either from memory or from MSAL.\n */\n getActiveAccount(): Promise<AuthenticationRecord | undefined>;\n /**\n * Calls to the implementation's doGetToken method.\n */\n getToken(scopes?: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken | null>;\n}\n"]}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
|
-
import { CredentialUnavailableError } from "../client/errors";
|
|
4
3
|
/**
|
|
5
4
|
* Error used to enforce authentication after trying to retrieve a token silently.
|
|
6
5
|
*/
|
|
7
|
-
export class AuthenticationRequiredError extends
|
|
6
|
+
export class AuthenticationRequiredError extends Error {
|
|
8
7
|
constructor(
|
|
9
8
|
/**
|
|
10
9
|
* The list of scopes for which the token will have access.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/msal/errors.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/msal/errors.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC;;GAEG;AACH,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IACpD;IACE;;OAEG;IACI,MAAgB;IACvB;;OAEG;IACI,kBAAmC,EAAE,EAC5C,OAAgB;QAEhB,KAAK,CAAC,OAAO,CAAC,CAAC;QAPR,WAAM,GAAN,MAAM,CAAU;QAIhB,oBAAe,GAAf,eAAe,CAAsB;QAI5C,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { GetTokenOptions } from \"@azure/core-auth\";\n\n/**\n * Error used to enforce authentication after trying to retrieve a token silently.\n */\nexport class AuthenticationRequiredError extends Error {\n constructor(\n /**\n * The list of scopes for which the token will have access.\n */\n public scopes: string[],\n /**\n * The options used to configure the getToken request.\n */\n public getTokenOptions: GetTokenOptions = {},\n message?: string\n ) {\n super(message);\n this.name = \"AuthenticationRequiredError\";\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flows.js","sourceRoot":"","sources":["../../../src/msal/flows.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AccessToken } from \"@azure/core-
|
|
1
|
+
{"version":3,"file":"flows.js","sourceRoot":"","sources":["../../../src/msal/flows.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AccessToken } from \"@azure/core-auth\";\n\nimport { CredentialLogger } from \"../util/logging\";\nimport { AuthenticationRecord } from \"./types\";\nimport { CredentialFlowGetTokenOptions } from \"./credentials\";\n\n/**\n * Union of the constructor parameters that all MSAL flow types take.\n * @internal\n */\nexport interface MsalFlowOptions {\n logger: CredentialLogger;\n clientId?: string;\n tenantId?: string;\n authorityHost?: string;\n authenticationRecord?: AuthenticationRecord;\n disableAutomaticAuthentication?: boolean;\n}\n\n/**\n * The common methods we use to work with the MSAL flows.\n * @internal\n */\nexport interface MsalFlow {\n /**\n * Allows for any setup before any request is processed.\n */\n init(options?: CredentialFlowGetTokenOptions): Promise<void>;\n /**\n * Tries to load the active account, either from memory or from MSAL.\n */\n getActiveAccount(): Promise<AuthenticationRecord | undefined>;\n /**\n * Tries to retrieve the token silently using MSAL.\n */\n getTokenSilent(scopes?: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;\n /**\n * Calls to the implementation's doGetToken method.\n */\n getToken(scopes?: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { credentialLogger } from "../../util/logging";
|
|
4
|
+
import { MsalNode } from "./nodeCommon";
|
|
5
|
+
/**
|
|
6
|
+
* This MSAL client sets up a web server to listen for redirect callbacks, then calls to the MSAL's public application's `acquireTokenByDeviceCode` during `doGetToken`
|
|
7
|
+
* to trigger the authentication flow, and then respond based on the values obtained from the redirect callback
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export class MsalAuthorizationCode extends MsalNode {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
super(options);
|
|
13
|
+
this.logger = credentialLogger("NodeJS MSAL Authorization Code");
|
|
14
|
+
this.redirectUri = options.redirectUri;
|
|
15
|
+
this.authorizationCode = options.authorizationCode;
|
|
16
|
+
if (options.clientSecret) {
|
|
17
|
+
this.msalConfig.auth.clientSecret = options.clientSecret;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async getAuthCodeUrl(options) {
|
|
21
|
+
await this.init();
|
|
22
|
+
return this.confidentialApp.getAuthCodeUrl(options);
|
|
23
|
+
}
|
|
24
|
+
async doGetToken(scopes, options) {
|
|
25
|
+
var _a;
|
|
26
|
+
try {
|
|
27
|
+
const result = await ((_a = this.confidentialApp) === null || _a === void 0 ? void 0 : _a.acquireTokenByCode({
|
|
28
|
+
scopes,
|
|
29
|
+
redirectUri: this.redirectUri,
|
|
30
|
+
code: this.authorizationCode
|
|
31
|
+
}));
|
|
32
|
+
// The Client Credential flow does not return an account,
|
|
33
|
+
// so each time getToken gets called, we will have to acquire a new token through the service.
|
|
34
|
+
return this.handleResult(scopes, this.clientId, result || undefined);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
throw this.handleError(scopes, err, options);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=msalAuthorizationCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msalAuthorizationCode.js","sourceRoot":"","sources":["../../../../src/msal/nodeFlows/msalAuthorizationCode.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAmB,QAAQ,EAAE,MAAM,cAAc,CAAC;AAYzD;;;;GAIG;AACH,MAAM,OAAO,qBAAsB,SAAQ,QAAQ;IAIjD,YAAY,OAAqC;QAC/C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,gBAAgB,CAAC,gCAAgC,CAAC,CAAC;QACjE,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;QACnD,IAAI,OAAO,CAAC,YAAY,EAAE;YACxB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;SAC1D;IACH,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAAkD;QACrE,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,eAAgB,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IAES,KAAK,CAAC,UAAU,CACxB,MAAgB,EAChB,OAAuC;;QAEvC,IAAI;YACF,MAAM,MAAM,GAAG,MAAM,CAAA,MAAA,IAAI,CAAC,eAAe,0CAAE,kBAAkB,CAAC;gBAC5D,MAAM;gBACN,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,IAAI,EAAE,IAAI,CAAC,iBAAiB;aAC7B,CAAC,CAAA,CAAC;YACH,yDAAyD;YACzD,8FAA8F;YAC9F,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,IAAI,SAAS,CAAC,CAAC;SACtE;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;SAC9C;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AccessToken } from \"@azure/core-auth\";\nimport { credentialLogger } from \"../../util/logging\";\nimport { CredentialFlowGetTokenOptions } from \"../credentials\";\nimport { MsalNodeOptions, MsalNode } from \"./nodeCommon\";\n\n/**\n * Options that can be passed to configure MSAL to handle authentication through opening a browser window.\n * @internal\n */\nexport interface MSALAuthorizationCodeOptions extends MsalNodeOptions {\n redirectUri: string;\n authorizationCode: string;\n clientSecret?: string;\n}\n\n/**\n * This MSAL client sets up a web server to listen for redirect callbacks, then calls to the MSAL's public application's `acquireTokenByDeviceCode` during `doGetToken`\n * to trigger the authentication flow, and then respond based on the values obtained from the redirect callback\n * @internal\n */\nexport class MsalAuthorizationCode extends MsalNode {\n private redirectUri: string;\n private authorizationCode: string;\n\n constructor(options: MSALAuthorizationCodeOptions) {\n super(options);\n this.logger = credentialLogger(\"NodeJS MSAL Authorization Code\");\n this.redirectUri = options.redirectUri;\n this.authorizationCode = options.authorizationCode;\n if (options.clientSecret) {\n this.msalConfig.auth.clientSecret = options.clientSecret;\n }\n }\n\n async getAuthCodeUrl(options: { scopes: string[]; redirectUri: string }): Promise<string> {\n await this.init();\n return this.confidentialApp!.getAuthCodeUrl(options);\n }\n\n protected async doGetToken(\n scopes: string[],\n options?: CredentialFlowGetTokenOptions\n ): Promise<AccessToken> {\n try {\n const result = await this.confidentialApp?.acquireTokenByCode({\n scopes,\n redirectUri: this.redirectUri,\n code: this.authorizationCode\n });\n // The Client Credential flow does not return an account,\n // so each time getToken gets called, we will have to acquire a new token through the service.\n return this.handleResult(scopes, this.clientId, result || undefined);\n } catch (err) {\n throw this.handleError(scopes, err, options);\n }\n }\n}\n"]}
|