node package manager


ADAL Cordova Plugin Patch For B2C


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


Via cordova CLI:

cordova plugin add

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

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: "[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(
// Use this when the user has already signed in recently... 
AzureB2C.acquireTokenSilentAsync = function(){
    return this.authContext.acquireTokenSilentAsync(
// Authentication Flow... 
// NOTE: this will fail if it is called before cordova's "ready" event 
AzureB2C.authenticate = function(clear){
    if(this.authContext === null){
        console.log("clearing cache before login...");
    var deferred = Q.defer();
    var loginSuccess = function(jwt){
        console.log("login success: " + JSON.stringify(jwt, null, "\t"));
        AzureB2C.authorizationHeader = "Bearer " + jwt.token;
    var loginError = function(error){
        console.log("login error: " + JSON.stringify(error, null, "\t"));
    var loudSignIn = function(){
        .then(loginSuccess, loginError);
    var parseCache = function(items){
        if(items.length > 0){
            console.log("cache has items, attempting silent login");
            .then(loginSuccess, loudSignIn);
        } else {
            console.log("cache is empty, attempting loud sign in");
    .then(parseCache, loudSignIn);
    return deferred.promise;
var onCordovaReady = function(){
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.