Add authentication to your Apache Cordova app

In this tutorial, you add Microsoft authentication to the quickstart project using Azure Active Directory. Before completing this tutorial, ensure you've created the project and enabled offline sync.

Configure your backend for authentication

To configure your backend for authentication, you must:

  • Create an app registration.
  • Configure Azure App Service Authentication and Authorization.
  • Add your app to the Allowed External Redirect URLs.

During this tutorial, we'll configure your app to use Microsoft authentication. An Azure Active Directory tenant has been configured automatically in your Azure subscription. You can use Azure Active Directory to configure Microsoft authentication.

You will need the URL of the Azure Mobile Apps service. The backend URL was provided when you created your project.

Create an app registration

  1. Sign in to the Azure portal.
  2. Select Azure Active Directory > App registrations > New registration.
  3. In the Register an application page, enter zumoquickstart in the Name field.
  4. Under Supported account types, select Accounts in any organizational directory (Any Azure AD directory - multitenant) and personal Microsoft accounts (e.g. Skype, Xbox).
  5. In Redirect URI, select Web and type <backend-url>/.auth/login/aad/callback. For example, if your backend URL is, you would enter
  6. Press the Register button at the bottom of the form.
  7. Copy the Application (client) ID.
  8. From the left pane, select Certificates & secrets > New client secret.
  9. Enter a suitable description, select a validity duration, then select Add.
  10. Copy the secret on the Certificates & secrets page. The value won't be displayed again.
  11. Select Authentication.
  12. Under Implicit grant and hybrid flows, enable ID tokens.
  13. Press Save at the top of the page.


The client secret value (password) is an important security credential. Don't share the password with anyone or distribute it within a client application.

Configure Azure App Service Authentication and Authorization

  1. In the Azure portal, select All Resources, then your App Service.
  2. Select Settings > Authentication.
  3. Press Add identity provider.
  4. Select Microsoft as the identity provider. This will provide a form to fill in.
  5. For App registration type, select Provide the details of an existing app registration.
  6. Paste the values you copied earlier into the Application (client) ID and Client secret boxes.
  7. For Issuer URL, enter This URL is the "magic tenant url" for Microsoft logins.
  8. For Restrict access, select Require authentication.
  9. For Unauthenticated request, select HTTP 401 Unauthorized.
  10. Press Add.
  11. Once the authentication screen returns, press Edit next to Authentication settings.
  12. In the Allowed external redirect URLs box, enter zumoquickstart://easyauth.callback.
  13. Press Save.

Step 10 requires that all users are authenticated before accessing your backend. You can provide fine-grained controls by adding code to your backend. For more information, see the Server SDK How-to for Node.js or ASP.NET Framework.

DID YOU KNOW? You can also allow users with organizational accounts in Azure Active Directory, Facebook, Google, Twitter, or any OpenID Connect compatible provider. Follow the instructions in the Azure App Service documentation.

Test that authentication is being requested

  • Run the app using cordova run android
  • Verify that an unhandled exception with a status code of 401 (Unauthorized) is raised after the app starts.

Add authentication to the app

To add authentication via the built-in provider, you must:

  • Add the authentication provider to the list of known good sources.
  • Call the authentication provider before accessing data.

Update the Content Security Policy

Each Apache Cordova app declares their known good sources via a Content-Security-Policy header. Each supported provider has an OAuth host that needs to be added:

Provider SDK Provider Name OAuth Host
Azure Active Directory aad
Facebook facebook
Google google
Twitter twitter

Edit www/index.html; add the OAuth host for Azure Active Directory as follows:

<meta http-equiv="Content-Security-Policy" content="
    default-src 'self' 
    data: gap:; 
    style-src 'self'; media-src *;">

The content is multiple lines for readability. Place all code on the same line.

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap:; style-src 'self'; media-src *;">

You have already replaced ZUMOAPPNAME with the name of your app.

Call the authentication provider

Edit www/js/index.js. Replace the setup() method with the following code:

function setup() {
    client.login('aad').then(function () {
        todoTable = client.getSyncTable('todoitem');
        addItemEl.addEventListener('submit', addItemHandler);
        refreshButtonEl.addEventListener('click', refreshDisplay);

Test the app

Run the following command:

cordova run android

Once the initial startup is complete, you'll be prompted to sign in with your Microsoft credentials. Once complete, you can add and delete items from the list.


If the emulator does not automatically start, open Android Studio, then select Configure > AVD Manager. This will allow you to start the device manually. If you run adb devices -l, you should see your selected emulated device.

Deleting the resources

Now you've completed the quickstart tutorial, you can delete the resources with az group delete -n zumo-quickstart. You can also delete the global app registration used for authentication through the portal.

Next steps

Take a look at the HOW TO sections:

You can also do a Quick Start for another platform using the same service: