Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

MS ADAL

Improve this doc

Active Directory Authentication Library (ADAL) plugin. Active Directory Authentication Library (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. Here you can find the source code for the library.

Repo: https://github.com/AzureAD/azure-activedirectory-library-for-cordova

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-ms-adal
    $ npm install --save @ionic-native/ms-adal@4
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { MSAdal, AuthenticationContext, AuthenticationResult } from '@ionic-native/ms-adal';


constructor(private msAdal: MSAdal) {}

...

let authContext: AuthenticationContext = this.msAdal.createAuthenticationContext('https://login.windows.net/common');

authContext.acquireTokenAsync('https://graph.windows.net', 'a5d92493-ae5a-4a9f-bcbf-9f1d354067d3', 'http://MyDirectorySearcherApp')
  .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));

Instance Members

createAuthenticationContext()

AuthenticationContext

Instance Members

authority()

validateAuthority()

tokenCache()

acquireTokenAsync(resourceUrl, clientId, redirectUrl, userId, extraQueryParameters)

Acquires token using interactive flow. It always shows UI and skips token from cache.

Param Type Details
resourceUrl String

Resource identifier

clientId String

Client (application) identifier

redirectUrl String

Redirect url for this application

userId String

User identifier (optional)

extraQueryParameters String

Extra query parameters (optional) Parameters should be escaped before passing to this method (e.g. using 'encodeURI()')

Returns: Promise Promise either fulfilled with AuthenticationResult object or rejected with error

acquireTokenSilentAsync(resourceUrl, clientId, userId)

Acquires token WITHOUT using interactive flow. It checks the cache to return existing result if not expired. It tries to use refresh token if available. If it fails to get token without displaying UI it will fail. This method guarantees that no UI will be shown to user.

Param Type Details
resourceUrl String

Resource identifier

clientId String

Client (application) identifier

userId String

User identifier (optional)

Returns: Promise Promise either fulfilled with AuthenticationResult object or rejected with error

AuthenticationResult

Param Type Details
accessToken string
accesSTokenType string
expiresOn Date
idToken string
isMultipleResourceRefreshToken boolean
status string
statusCode number
tenantId string
userInfo UserInfo
createAuthorizationHeader string

Creates authorization header for web requests.

TokenCache

Param Type Details
clear void
readItems Promise<TokenCacheItem[]>
deleteItem void

TokenCacheItem

Param Type Details
accessToken string
authority string
clientId string
displayableId string
expiresOn Date
isMultipleResourceRefreshToken boolean
resource string
tenantId string
userInfo UserInfo

UserInfo

Param Type Details
displayableId string
userId string
familyName string
givenName string
identityProvider string
passwordChangeUrl string
passwordExpiresOn Date
uniqueId string

API

Native

General