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

msal

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

msal

Microsoft Authentication Library for js

  • 1.4.18
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
267K
increased by1.48%
Maintainers
1
Weekly downloads
 
Created

What is msal?

The msal (Microsoft Authentication Library) npm package is used to authenticate users and acquire tokens to access protected resources such as Microsoft Graph, other Microsoft APIs, or your own APIs. It supports various authentication flows and can be used in different environments including single-page applications (SPA), server-side applications, and mobile apps.

What are msal's main functionalities?

User Authentication

This code demonstrates how to configure the msal package for user authentication in a Node.js application. It sets up the client application with the necessary credentials and generates an authorization code URL.

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

const config = {
  auth: {
    clientId: 'your_client_id',
    authority: 'https://login.microsoftonline.com/your_tenant_id',
    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);
}).catch((error) => console.log(JSON.stringify(error)));

Token Acquisition

This code demonstrates how to acquire an access token using an authorization code. The access token can then be used to access protected resources.

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

cca.acquireTokenByCode(tokenRequest).then((response) => {
  console.log('Access token:', response.accessToken);
}).catch((error) => console.log(JSON.stringify(error)));

Silent Token Acquisition

This code demonstrates how to silently acquire an access token for a user who is already signed in, without requiring user interaction.

const silentRequest = {
  account: account,
  scopes: ['user.read']
};

cca.acquireTokenSilent(silentRequest).then((response) => {
  console.log('Access token:', response.accessToken);
}).catch((error) => console.log(JSON.stringify(error)));

Other packages similar to msal

Keywords

FAQs

Package last updated on 01 May 2023

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