Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@azure/msal-node

Package Overview
Dependencies
Maintainers
3
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@azure/msal-node

Microsoft Authentication Library for Node

  • 1.9.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.6M
decreased by-23.96%
Maintainers
3
Weekly downloads
 
Created

What is @azure/msal-node?

The @azure/msal-node package is a Microsoft library that enables Node.js applications to authenticate users and access secured resources in the Microsoft identity platform, such as Microsoft 365, Azure, and other resources that rely on Microsoft accounts. It supports various OAuth 2.0 and OpenID Connect flows.

What are @azure/msal-node's main functionalities?

Authentication

This code sample demonstrates how to configure the MSAL client and get an authorization code URL, which is the first step in the OAuth 2.0 authorization code flow.

const msal = require('@azure/msal-node');

const config = {
  auth: {
    clientId: 'your_client_id',
    authority: 'https://login.microsoftonline.com/common',
    clientSecret: 'your_client_secret',
  }
};

const cca = new msal.ConfidentialClientApplication(config);

const authCodeUrlParameters = {
  scopes: ['user.read'],
  redirectUri: 'http://localhost:3000/redirect',
};

cca.getAuthCodeUrl(authCodeUrlParameters).then((response) => {
  console.log(response);
});

Acquiring Tokens

This code sample shows how to exchange an authorization code for an access token, which can be used to access secured resources.

const tokenRequest = {
  code: 'authorization_code_received_from_auth_code_url',
  scopes: ['user.read'],
  redirectUri: 'http://localhost:3000/redirect',
};

cca.acquireTokenByCode(tokenRequest).then((response) => {
  console.log(response);
}).catch((error) => {
  console.error(error);
});

Silent Token Acquisition

This code sample illustrates how to silently acquire an access token using a cached account, which is useful for renewing tokens without user interaction.

const silentTokenRequest = {
  account: cca.getAccountByHomeId('user_home_id'),
  scopes: ['user.read'],
};

cca.acquireTokenSilent(silentTokenRequest).then((response) => {
  console.log(response);
}).catch((error) => {
  if (error instanceof msal.InteractionRequiredAuthError) {
    // Fallback to interactive method if silent acquisition fails
  }
});

Other packages similar to @azure/msal-node

Keywords

FAQs

Package last updated on 02 May 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc