-
Notifications
You must be signed in to change notification settings - Fork 374
Login APIs
ADAL JS provides two ways for your application to sign-in users with Azure AD accounts.
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()
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();
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).
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.