Skip to content

lobo/Auth0AzureIntegration

 
 

Repository files navigation

Auth0AzureIntegration

This sample explains how to integrate Auth0 into your Windows Azure application while authenticating with a Microsoft Account.

Actually, it is a Windows Azure Mobile App example, which you can download from the Azure portal, but that has been modified in order to use Auth0 authentication.

Step 1: Create an Azure Mobile App

You need to create an Azure Mobile App as described here. Then as Step III from that tutorial explains, go ahead and download the Azure test application.

Step 2: Configure a Microsoft Account

In the Auth0 Dashboard: configure a Microsoft Account as described here. Microsoft Account

Step 3: Set up Authentication on the Azure App Service

Log onto the Azure Portal, click on All Resources, then go to your Azure Mobile App application (the one from Step 1).

Click on All Settings, then Authentication / Authorization. Now you are in the right place to start setting up the authentication.

Now we have to turn App Service Authentication on. Set the action you will take when the request is not authenticated to have the value Allow request. In the Advance Settings section you may turn the Token Store to on.

Now click on your Microsoft Account. Cut and paste the Client ID and Client Secret from Step 2, and select the same boxes as you did in Step 2 – these are the claims you are requesting to be provided to you. Azure Portal

Step 4: Restrict permissions to authenticated users

In your Mobile App's Settings, click Easy Tables and select your table. Click Change permissions, select Authenticated access only for all permissions, then click Save.

Step 5: Auth0: Enabling WAMS add-on for your client

In the Auth0 Dashboard, head to: Clients -> your client -> Addons -> Microsoft Azure Mobile Services

NOTE: With App Services/Mobile Apps, the master key is no longer used/required, that is why it is no longer available on the portal. You can just enter some symbols in the field Master Key.

Now you have to integrate Auth0 into your Azure application.

In your Podfile add the following:

pod 'Lock', '~> 1.26'
pod 'SimpleKeychain'

Add Auth0ClientId and Auth0Domain to your Info.plist file.

Important snippets

  • Note: All these snippets are located in the AppDelegate.swift, LoginViewController.swift and ToDoTableViewController.swift files.

1. Register the authenticator

    let windowslive = A0WebViewAuthenticator(connectionName: "windowslive", lock: A0Lock.sharedLock())
    A0Lock.sharedLock().registerAuthenticators([windowslive]);

2. Login to Microsoft Account

    A0Lock.sharedLock().identityProviderAuthenticator().authenticateWithConnectionName("windowslive", 
	parameters: nil, success: success, failure: failure)

3. Get a delegation token for WAMS as described here

  let idToken = ...
  let dictionary = [
            “id_token": idToken,
    A0ParameterAPIType: "wams"]
  let parameters = A0AuthParameters.newWithDictionary(dictionary)
        
  A0Lock.sharedLock().apiClient().fetchDelegationTokenWithParameters(parameters,
    success:success, failure:failure);

4. Use the delegation token for WAMS

  let client = MSClient(applicationURLString: "https://<Your_Azure_Mobile_App_Name>.azurewebsites.net")
        
  let token = //delegation token
  let userId = //Microsoft Account user id
  let user:MSUser = MSUser(userId: userId)
  user.mobileServiceAuthenticationToken = token;        
  client.currentUser = user;

Before using the example please make sure that you change some keys in Info.plist with your data:

  • Auth0ClientId
  • Auth0Domain

For more information about integrating Auth0 with Azure Mobile Apps please check the following links:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 88.0%
  • Swift 11.9%
  • Ruby 0.1%