Socket
Socket
Sign inDemoInstall

@azure/msal-browser

Package Overview
Dependencies
Maintainers
3
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@azure/msal-browser

Microsoft Authentication Library for js


Version published
Weekly downloads
3.8M
increased by2.11%
Maintainers
3
Weekly downloads
 
Created

What is @azure/msal-browser?

The @azure/msal-browser package is a library that enables browser-based applications to authenticate users using Azure Active Directory and to obtain tokens to access protected APIs. It implements the OAuth 2.0 and OpenID Connect protocols in a client-side JavaScript application.

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

Authentication

This feature allows users to sign in and obtain an ID token through a popup window.

const msalConfig = {
  auth: {
    clientId: 'your-client-id',
    authority: 'https://login.microsoftonline.com/common',
    redirectUri: 'your-redirect-uri'
  }
};

const myMSALObj = new msal.PublicClientApplication(msalConfig);

function signIn() {
  myMSALObj.loginPopup()
    .then(loginResponse => {
      console.log('id_token acquired at: ' + new Date().toString());
      if (myMSALObj.getAccount()) {
        console.log('Logged in');
      }
    }).catch(error => {
      console.error(error);
    });
}

Acquiring Tokens

This feature is used to acquire tokens silently or through a popup if required by the application.

const tokenRequest = {
  scopes: ['user.read'],
  forceRefresh: false
};

function getTokenPopup(request) {
  return myMSALObj.acquireTokenSilent(request)
    .catch(error => {
      console.warn('silent token acquisition fails. acquiring token using popup');
      if (error instanceof msal.InteractionRequiredAuthError) {
        return myMSALObj.acquireTokenPopup(request)
          .then(tokenResponse => {
            return tokenResponse;
          }).catch(error => {
            console.error(error);
          });
      } else {
        console.warn(error);
      }
    });
}

Single Sign-Out

This feature allows users to sign out of the application and clear the user's session.

function signOut() {
  const logoutRequest = {
    account: myMSALObj.getAccount()
  };
  myMSALObj.logout(logoutRequest);
}

Other packages similar to @azure/msal-browser

Keywords

FAQs

Package last updated on 08 Oct 2024

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