npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

adal-angular-core

v1.0.20

Published

Windows Azure Active Directory Client Library for js

Downloads

14

Readme

Active Directory Authentication Library (ADAL) for JavaScript

|Getting Started| Docs| Samples| Support | --- | --- | --- | --- |

Active Directory Authentication Library for JavaScript (ADAL JS) helps you to use Azure AD for handling authentication in your single page applications. This library works with both plain JS as well as AngularJS applications.

Build Statusnpmnpm

Installation

You have multiple ways of getting ADAL JS:

Via NPM (https://www.npmjs.com/package/adal-angular-core):

npm install adal-angular-core

Note: Currently there is one NPM package providing both the plain JS library (adal.js) and the AngularJS wrapper (adal-angular.js).

Via CDN:

<!-- Latest compiled and minified JavaScript -->
<script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.20/js/adal.min.js"></script>
<script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.20/js/adal-angular.min.js"></script>

Usage

Prerequisite

Before using ADAL JS, follow the instructions to register your application on the Azure portal. Also, make sure to enable the OAuth 2.0 implicit flow by setting the property oauth2AllowImplicitFlow to true by editing your application manifest on the portal. Implicit flow is used by ADAL JS to get tokens.

1. Instantiate the AuthenticationContext

Instantiate the global variable AuthenticationContext with a minimal required config of clientID. You can read about other configurable options here.

window.config = {
    clientId: '[Enter your client_id here, e.g. g075edef-0efa-453b-997b-de1337c29185]',
    popUp: true,
    callback : callbackFunction
};

var authContext = new AuthenticationContext(config);

function callbackFunction(errorDesc, token, error, tokenType)
{
}

2. Login the user

Your app must login the user to establish user context. The login operates in popup mode if you set the option popUp: true instead of a full redirect as shown in the config above.Defaults to `false. The callback function passed in the Authentication request constructor will be called after the login with success or failure results.

var user = authenticationContext.getCachedUser();
if (user) {
    // Use the logged in user information to call your own api
    onLogin(null, user);
}
else {
    // Initiate login
    authenticationContext.login();
}

3. Get an access token

Next, you can get access tokens for the APIs your app needs to call using the acquireToken method which attempts to acquire token silently. The acquireToken method takes a callback function as shown below.

If the silent token acquisition fails for some reasons such as an expired session or password change, you will need to invoke one of the interactive methods to acquire tokens.

authenticationContext.acquireToken(webApiConfig.resourceId, function (errorDesc, token, error) {
    if (error) { //acquire token failure
        if (config.popUp) {
            // If using popup flows
            authenticationContext.acquireTokenPopup(webApiConfig.resourceId, null, null,  function (errorDesc, token, error) {});
        }
        else {
        // In this case the callback passed in the Authentication request constructor will be called.
            authenticationContext.acquireTokenRedirect(webApiConfig.resourceId, null, null);
        }
    }
    else {
        //acquired token successfully
    }
});
}

Note: In ADAL JS, you will have to explicitly call the handleWindowCallback method on page load to handle the response from the server in case of redirect flows like login without popup and acquireTokenRedirect. There is no need to call this function for popup flows like loginPopup and acquireTokenPopup. This method must be called for processing the response received from AAD. It extracts the hash, processes the token or error, saves it in the cache and calls the registered callback function in your initialization with the result.

if (authenticationContext.isCallback(window.location.hash)) {
    authenticationContext.handleWindowCallback();
}

4. Use the token as a bearer in an HTTP request to call the Microsoft Graph or a Web API

    var headers = new Headers();
    var bearer = "Bearer " + token;
    headers.append("Authorization", bearer);
    var options = {
         method: "GET",
         headers: headers
    };
    var graphEndpoint = "https://graph.microsoft.com/v1.0/me";

    fetch(graphEndpoint, options)
        .then(function (response) {
             //do something with response
        }

You can learn further details about ADAL.js functionality documented in the ADAL Wiki and find complete code samples.