In this blog post I will explain how to get started with the Ionic Native plugin MS ADAL (Active Direcotry Authentication Library). The ADAL plugin provides easy to use authentication functionality for your Apache Cordova apps by taking advantage of Windows Server Active Directory and Windows Azure Active Directory.
Before we get started there are a few important things that you need to know:
- The plugin will only work on a simulator or a real device meaning that you won't be able to run cordova and test it in your browser
- You need to get yourself a free Azure AD account
- Supported platforms are Android, iOS and Windows
Let's get started.
1) Install Ionic 3
The easy way of installing ionic is by using npm. You can find the Ionic instructions here. If you don't wish to read them just follow this tutorial, but I won't be going into much detail as you should be already experienced at least a little bit with the framework.
Install Ionic
npm install -g ionic
Start an app
ionic start myApp tabs
Run your app
cd myApp
ionic serve
If at this point everything works - that's great! In the next step we will have to install the MsADAL plugin.
2) Install MSAdal
First of all the full documentation can be found here. Make sure you read it or at least have a look as their installation guides are fairly clear.
To install the plugin we'll use npm again.
- Install the Cordova and Ionic Native plugins:
ionic cordova plugin add cordova-plugin-ms-adal
npm install --save @ionic-native/ms-adal
Now that we have installed MSAdal we need to add it to our app.module.ts file:
1- Start by importing the MSAdal
2 - Add MSAdal to your Providers
import { MSAdal } from'@ionic-native/ms-adal';

import { MSAdal, AuthenticationContext, AuthenticationResult } from '@ionic-native/ms-adal';
private msAdal: MSAdal
onLogin(){
let authContext: AuthenticationContext = this.msAdal.createAuthenticationContext('https://login.windows.net/common');
authContext.acquireTokenAsync('https://graph.windows.net', 'clienID-replace-this', 'http://localhost:8000','','')
.then((authResponse: AuthenticationResult) => {
console.log('Token is' , authResponse.accessToken);
console.log('Token will expire on', authResponse.expiresOn);
})
.catch((e: any) => console.log('Authentication failed', e));
}

3) Configuration - App Registration



4) Testing
ionic cordova run android
ionic cordova run ios