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

cordova-plugin-ms-adal-b2c-patch

v0.8.0

Published

Provides Microsoft Azure Active Directory (ADAL) OAuth client.

Downloads

4

Readme

ADAL Cordova Plugin Patch For B2C

Overview

This is a chopped version of cordova-plugin-ms-adal that works with Azure AD B2C.

Be forewarned that this patch is barely working, with minimal "happy-path" testing, and I do not intend to maintain it after the original plugin libraries get updated.

  • Android - ADAL library has been updated to 2.0.3-alpha and now has policies / tokens integrated correctly

  • iOS - ADAL library has been updated to 3.0.0-pre6 and works correctly with B2C, token caching now works as well

  • Windows - currently no plans to update this platform's support

Installation

Via cordova CLI:

cordova plugin add https://github.com/jospete/azure-activedirectory-library-for-cordova

NOTE - this patch will conflict with the original plugin if the original already exists in your project. The original plugin must be replaced by this one. This plugin is tagged as "cordova-plugin-ms-adal-b2c-patch", so you should delete "cordova-plugin-ms-adal" in your /plugins directory if that exists.

Sample Usage

require("Q");

var AzureB2C = {
    
    // ADAL AuthenticationContext instance, must not be set before cordova is ready
    authContext: null,
    
    // use this to make API requests after login
    authorizationHeader: null,
    
    // default to use
    redirectUrl: "urn:ietf:wg:oauth:2.0:oob",
    
    // default used by the updated ADAL libraries
    extraQueryParams: "nux=1",
    
    // ** required **
    authority: "https://login.microsoftonline.com/[YOUR_TENANT]",
    
    // ** required ** also sometimes called "App ID", looks something like this: f6dad784-f7d3-****-92bd-******
    clientId: "[YOUR_CLIENT_ID]",
    
    // ** required **
    policy: "[YOUR_SIGNIN_POLICY]",
    
    // don't need to track this in most cases
    userId: null,
    
    // legacy - no longer needed in the updated ADAL libraries
    resourceUrl: ""
};

AzureB2C.createContext = function(){
    this.authContext = new Microsoft.ADAL.AuthenticationContext(this.authority);
};

// Use this to do a loud sign in initially...
AzureB2C.acquireTokenAsync = function(){
    return this.authContext.acquireTokenAsync(
        this.resourceUrl,
        this.clientId,
        this.redirectUrl,
        this.userId,
        this.extraQueryParams,
        this.policy
    );
};

// Use this when the user has already signed in recently...
AzureB2C.acquireTokenSilentAsync = function(){
    return this.authContext.acquireTokenSilentAsync(
        this.resourceUrl,
        this.clientId,
        this.userId,
        this.redirectUrl,
        this.policy
    );
};

// Authentication Flow...
// NOTE: this will fail if it is called before cordova's "ready" event
AzureB2C.authenticate = function(clear){
    
    if(this.authContext === null){
        this.createContext();
    }
    
    if(clear){
        console.log("clearing cache before login...");
        this.authContext.tokenCache.clear();
    }

    var deferred = Q.defer();
    
    var loginSuccess = function(jwt){
        console.log("login success: " + JSON.stringify(jwt, null, "\t"));
        AzureB2C.authorizationHeader = "Bearer " + jwt.token;
        deferred.resolve(jwt);
    };
    
    var loginError = function(error){
        console.log("login error: " + JSON.stringify(error, null, "\t"));
        deferred.reject(error);
    };

    var loudSignIn = function(){
        AzureB2C.acquireTokenAsync()
        .then(loginSuccess, loginError);
    };

    var parseCache = function(items){

        if(items.length > 0){
            console.log("cache has items, attempting silent login");
            AzureB2C.acquireTokenSilentAsync()
            .then(loginSuccess, loudSignIn);
            
        } else {
            console.log("cache is empty, attempting loud sign in");
            loudSignIn(); 
        }
    };

    this.authContext.tokenCache.readItems()
    .then(parseCache, loudSignIn);

    return deferred.promise;
};

var onCordovaReady = function(){
    AzureB2C.authenticate();
};

document.addEventListener("deviceready", onCordovaReady, false);

Build / Update ADALiOS.framework (iOS)

NOTE: you shouldn't need to do this since the correct ADAL iOS version is baked into this project, but I've added this in for better insight on how the whole thing works.

** This is not guaranteed to be functional - I barely got it running when I rebuilt the framework libs. **

at the root of this project:

  • npm install
  • gulp ios-update-adal

See gulpfile.js for details on how this works

Other Documentation

See the original plugin docs for more info on how all of this works / should be used.