What is @azure/msal-common?
The @azure/msal-common package is a Microsoft library that provides the core functionality for the authentication protocols OAuth 2.0 and OpenID Connect. It is primarily used in the development of applications that require secure access to Microsoft Azure services. The package serves as a common foundation for other Microsoft authentication libraries, enabling developers to implement authentication features efficiently.
What are @azure/msal-common's main functionalities?
Token Acquisition
This feature allows developers to acquire tokens for accessing secured resources. The code sample demonstrates how to acquire a token using a username and password.
const msal = require('@azure/msal-common');
const pca = new msal.PublicClientApplication({ auth: { clientId: 'your-client-id' } });
pca.acquireTokenByUsernamePassword({
scopes: ['user.read'],
username: 'user@example.com',
password: 'your-password'
}).then(response => console.log(response)).catch(error => console.error(error));
Token Caching
Token caching is crucial for efficient authentication management, reducing the need to request new tokens for each operation. The code sample shows how to read token cache from storage.
const { TokenCache } = require('@azure/msal-common');
const cache = new TokenCache();
cache.readFromStorage('your-storage-key').then(() => {
const accountInfo = cache.getAccount('user@example.com');
console.log(accountInfo);
});
Account Management
This feature facilitates the management of user accounts in an application. The code sample retrieves account information based on the username.
const msal = require('@azure/msal-common');
const pca = new msal.PublicClientApplication({ auth: { clientId: 'your-client-id' } });
pca.getAccountByUsername('user@example.com').then(account => {
console.log(account);
}).catch(error => console.error(error));
Other packages similar to @azure/msal-common
passport-azure-ad
This package is a collection of Passport Strategies to help you integrate with Azure Active Directory. It is similar to @azure/msal-common but is specifically tailored for Node.js applications using Passport.js, making it more suitable for applications that already use Passport.js for other authentication needs.
oidc-client
oidc-client is a client-side library to help with OpenID Connect (OIDC) and OAuth2 protocol flows in web, desktop, and mobile applications. Unlike @azure/msal-common, which is optimized for Azure services, oidc-client is more generic and can be used with any OIDC-compliant identity provider.
Microsoft Authentication Library for JavaScript (MSAL.js) Common Protocols Package
- About
- FAQ
- Changelog
- Releases
- Prerequisites and Usage
- Installation
- Security Reporting
- License
- Code of Conduct
About
The MSAL library for JavaScript enables client-side JavaScript applications to authenticate users using Azure AD work and school accounts (AAD), Microsoft personal accounts (MSA) and social identity providers like Facebook, Google, LinkedIn, Microsoft accounts, etc. through Azure AD B2C service. It also enables your app to get tokens to access Microsoft Cloud services such as Microsoft Graph.
The @azure/msal-common
package described by the code in this folder serves as a common package dependency for the @azure/msal-browser
package (and in the future, the msal-node package). Be aware that this is an internal library, and is subject to frequent change. It is not meant for production consumption by itself.
FAQ
See here.
Prerequisites and Usage
This library is not meant for production use. Please use one of these packages specific to the platform you are developing for:
Installation
Via NPM:
npm install @azure/msal-common
Security Reporting
If you find a security issue with our libraries or services please report it to secure@microsoft.com with as much detail as possible. Your submission may be eligible for a bounty through the Microsoft Bounty program. Please do not post security issues to GitHub Issues or any other public site. We will contact you shortly upon receiving the information. We encourage you to get notifications of when security incidents occur by visiting this page and subscribing to Security Advisory Alerts.
License
Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License (the "License");
We Value and Adhere to the Microsoft Open Source Code of Conduct
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.