Skip to content
This repository has been archived by the owner on Jun 26, 2021. It is now read-only.

Login APIs

wenYorker edited this page Jul 12, 2018 · 1 revision

ADAL JS provides two ways for your application to sign-in users with Azure AD accounts.

Login with a redirect

This is the default method which the library provides to log in users. You can invoke this as follows:

var authContext = new AuthenticationContext(config);

authContext.login()

Login in a pop-up window

The library provides this approach for developers building apps where they want to remain on the page and authenticate the user through a popup window.

window.config = {
  clientId: 'clientId',
  popUp: true
};

var authContext = new AuthenticationContext(config);

authContext.login();

ID tokens and User info

ADAL JS uses the OAuth 2.0 implicit flow. As a result, the sign-in flow in ADAL JS authenticates the user with Azure AD and also gets an ID token for your application. The ID token contains claims about the user which are exposed in the user.profile property in ADAL JS . You can get user information as follows:

var user = authContext.getCachedUser();
var username = user.userName;
var upn = user.profile.upn;

Note: The ID token can also be used to make secure API calls to your application's own backend API (which is registered in Azure AD as the same web app).

Logout

When the logout method is called, the library clears the application cache in the browser storage and sends a logout request to the Azure AD instance's logout endpoint.

authContext.logOut();

The default behavior is to redirect the user to window.location.href after logout. If a postLogoutRedirectUri value is set at the config time, the user will be redirected to that URI.

Clone this wiki locally