@azure/identity
Advanced tools
Comparing version 4.1.0-alpha.20240305.3 to 4.1.0-alpha.20240308.3
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import * as msal from "@azure/msal-node"; | ||
import { generatePluginConfiguration } from "./msalPlugins"; | ||
import { msalPlugins } from "./msalPlugins"; | ||
import { credentialLogger, formatSuccess } from "../../util/logging"; | ||
import { defaultLoggerCallback, ensureValidMsalToken, getAuthority, getKnownAuthorities, getMSALLogLevel, publicToMsal, } from "../utils"; | ||
import { defaultLoggerCallback, ensureValidMsalToken, getAuthority, getKnownAuthorities, getMSALLogLevel, handleMsalError, publicToMsal, } from "../utils"; | ||
import { AuthenticationRequiredError } from "../../errors"; | ||
@@ -62,15 +62,21 @@ import { IdentityClient } from "../../client/identityClient"; | ||
: null, | ||
pluginConfiguration: generatePluginConfiguration(createMsalClientOptions), | ||
pluginConfiguration: msalPlugins.generatePluginConfiguration(createMsalClientOptions), | ||
}; | ||
let confidentialApp = undefined; | ||
async function getConfidentialApp(_options = {}) { | ||
// abort requests | ||
if (confidentialApp === undefined) { | ||
// TODOs: | ||
// CAE / non-CAE | ||
confidentialApp = new msal.ConfidentialClientApplication(Object.assign(Object.assign({}, state.msalConfig), { broker: { nativeBrokerPlugin: state.pluginConfiguration.broker.nativeBrokerPlugin }, cache: { cachePlugin: await state.pluginConfiguration.cache.cachePlugin } })); | ||
const confidentialApps = new Map(); | ||
async function getConfidentialApp(options = {}) { | ||
const appKey = options.enableCae ? "CAE" : "default"; | ||
let confidentialClientApp = confidentialApps.get(appKey); | ||
if (confidentialClientApp) { | ||
return confidentialClientApp; | ||
} | ||
return confidentialApp; | ||
// Initialize a new app and cache it | ||
const cachePlugin = options.enableCae | ||
? state.pluginConfiguration.cache.cachePluginCae | ||
: state.pluginConfiguration.cache.cachePlugin; | ||
state.msalConfig.auth.clientCapabilities = options.enableCae ? ["cp1"] : undefined; | ||
confidentialClientApp = new msal.ConfidentialClientApplication(Object.assign(Object.assign({}, state.msalConfig), { broker: { nativeBrokerPlugin: state.pluginConfiguration.broker.nativeBrokerPlugin }, cache: { cachePlugin: await cachePlugin } })); | ||
confidentialApps.set(appKey, confidentialClientApp); | ||
return confidentialClientApp; | ||
} | ||
async function getTokenSilent(app, scopes, options) { | ||
async function getTokenSilent(app, scopes, options = {}) { | ||
if (state.cachedAccount === null) { | ||
@@ -92,3 +98,8 @@ const cache = app.getTokenCache(); | ||
} | ||
// TODO: broker | ||
// Keep track and reuse the claims we received across challenges | ||
if (options.claims) { | ||
state.cachedClaims = options.claims; | ||
} | ||
// TODO: port over changes for broker | ||
// https://github.com/Azure/azure-sdk-for-js/blob/727a7208251961b5036d8e1d86edaa944c42e3d6/sdk/identity/identity/src/msal/nodeFlows/msalNodeCommon.ts#L383-L395 | ||
msalLogger.getToken.info("Attempting to acquire token silently"); | ||
@@ -98,3 +109,3 @@ return app.acquireTokenSilent({ | ||
scopes, | ||
claims: options === null || options === void 0 ? void 0 : options.claims, | ||
claims: state.cachedClaims, | ||
}); | ||
@@ -132,3 +143,8 @@ } | ||
if (response === null) { | ||
response = await onAuthenticationRequired(); | ||
try { | ||
response = await onAuthenticationRequired(); | ||
} | ||
catch (err) { | ||
throw handleMsalError(scopes, err, options); | ||
} | ||
} | ||
@@ -135,0 +151,0 @@ // At this point we should have a token, process it |
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import { CACHE_CAE_SUFFIX, CACHE_NON_CAE_SUFFIX } from "../../constants"; | ||
/** | ||
@@ -44,3 +45,3 @@ * The current persistence provider, undefined by default. | ||
*/ | ||
export function generatePluginConfiguration(options) { | ||
function generatePluginConfiguration(options) { | ||
var _a, _b, _c, _d, _e; | ||
@@ -63,3 +64,4 @@ const config = { | ||
} | ||
config.cache.cachePlugin = persistenceProvider(options.tokenCachePersistenceOptions); | ||
config.cache.cachePlugin = persistenceProvider(Object.assign({ name: `${options.tokenCachePersistenceOptions.name}.${CACHE_NON_CAE_SUFFIX}` }, options.tokenCachePersistenceOptions)); | ||
config.cache.cachePluginCae = persistenceProvider(Object.assign({ name: `${options.tokenCachePersistenceOptions.name}.${CACHE_CAE_SUFFIX}` }, options.tokenCachePersistenceOptions)); | ||
} | ||
@@ -79,2 +81,8 @@ if ((_e = options.brokerOptions) === null || _e === void 0 ? void 0 : _e.enabled) { | ||
} | ||
/** | ||
* Wraps generatePluginConfiguration as a writeable property for test stubbing purposes. | ||
*/ | ||
export const msalPlugins = { | ||
generatePluginConfiguration, | ||
}; | ||
//# sourceMappingURL=msalPlugins.js.map |
{ | ||
"name": "@azure/identity", | ||
"sdk-type": "client", | ||
"version": "4.1.0-alpha.20240305.3", | ||
"version": "4.1.0-alpha.20240308.3", | ||
"description": "Provides credential implementations for Azure SDK libraries that can authenticate with Microsoft Entra ID", | ||
@@ -52,3 +52,3 @@ "main": "dist/index.js", | ||
"build": "npm run clean && npm run extract-api && tsc -p . && dev-tool run bundle", | ||
"clean": "rimraf dist dist-* types *.tgz *.log", | ||
"clean": "rimraf --glob dist dist-* types *.tgz *.log", | ||
"execute:samples": "dev-tool samples run samples-dev", | ||
@@ -59,3 +59,3 @@ "extract-api": "tsc -p . && api-extractor run --local", | ||
"integration-test:browser": "echo skipped", | ||
"integration-test:node": "dev-tool run test:node-ts-input -- --timeout 180000 'test/public/node/*.spec.ts' 'test/internal/node/*.spec.ts'", | ||
"integration-test:node": "dev-tool run test:node-js-input -- --timeout 180000 'dist-esm/test/public/node/*.spec.js' 'dist-esm/test/internal/node/*.spec.js'", | ||
"integration-test": "npm run integration-test:node && npm run integration-test:browser", | ||
@@ -160,3 +160,3 @@ "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]", | ||
"puppeteer": "^22.2.0", | ||
"rimraf": "^3.0.0", | ||
"rimraf": "^5.0.5", | ||
"sinon": "^17.0.0", | ||
@@ -163,0 +163,0 @@ "ts-node": "^10.0.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1511255
11674