Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@azure/identity-cache-persistence
Advanced tools
Readme
This package provides a plugin to the Azure Identity library for JavaScript (@azure/identity
) that enables persistent token caching. Token cache persistence allows the built-in token cache to persist across sessions using a secure storage system provided by the local operating system.
const { useIdentityPlugin } = require("@azure/identity");
const { cachePersistencePlugin } = require("@azure/identity-cache-persistence");
useIdentityPlugin(cachePersistencePlugin);
This package is designed to be used with Azure Identity for JavaScript. Install both @azure/identity
and this package using npm
:
$ npm install --save @azure/identity
$ npm install --save @azure/identity-cache-persistence
Azure Identity plugins for JavaScript support stable (even numbered) versions of Node.js starting from v12. While the plugins may run in other Node versions, no support is guaranteed. @azure/identity-cache-persistence
does not support browser environments.
If this is your first time using @azure/identity
or Microsoft Entra ID, we recommend that you read Using @azure/identity
with Microsoft Entra ID first. This document will give you a deeper understanding of the platform and how to configure your Azure account correctly.
As of @azure/identity
version 2.0.0, the Identity client library for JavaScript includes a plugin API. This package (@azure/identity-cache-persistence
) exports a plugin object that you must pass as an argument to the top-level useIdentityPlugin
function from the @azure/identity
package. Enable token cache persistence in your program as follows:
const { useIdentityPlugin } = require("@azure/identity");
const { cachePersistencePlugin } = require("@azure/identity-cache-persistence");
useIdentityPlugin(cachePersistencePlugin);
After calling useIdentityPlugin
, the persistent token cache plugin is registered to the @azure/identity
package and will be available on all credentials that support persistent token caching (those that have tokenCachePersistenceOptions
in their constructor options).
Once the plugin is registered, you can enable token cache persistence by passing tokenCachePersistenceOptions
with an enabled
property set to true
to a credential constructor. In the following example, we use the DeviceCodeCredential
, since persistent caching of its tokens allows you to skip the interactive device-code authentication flow if a cached token is available.
const { useIdentityPlugin, DeviceCodeCredential } = require("@azure/identity");
const { cachePersistencePlugin } = require("@azure/identity-cache-persistence");
useIdentityPlugin(cachePersistencePlugin);
async function main() {
const credential = new DeviceCodeCredential({
tokenCachePersistenceOptions: {
enabled: true,
},
});
// We'll use the Microsoft Graph scope as an example
const scope = "https://graph.microsoft.com/.default";
// Print out part of the access token
console.log((await credential.getToken(scope)).token.substr(0, 10), "...");
}
main().catch((error) => {
console.error("An error occurred:", error);
process.exit(1);
});
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL
environment variable to info
. Alternatively, logging can be enabled at runtime by calling setLogLevel
in the @azure/logger
:
const { setLogLevel } = require("@azure/logger");
setLogLevel("info");
If you encounter bugs or have suggestions, please open an issue.
If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.
FAQs
A secure, persistent token cache for Azure Identity credentials that uses the OS secret-management API
The npm package @azure/identity-cache-persistence receives a total of 3,048 weekly downloads. As such, @azure/identity-cache-persistence popularity was classified as popular.
We found that @azure/identity-cache-persistence demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.