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.
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.
In the Auth0 Dashboard: configure a Microsoft Account as described here.
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.
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
.
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.
- Note: All these snippets are located in the
AppDelegate.swift
,LoginViewController.swift
andToDoTableViewController.swift
files.
let windowslive = A0WebViewAuthenticator(connectionName: "windowslive", lock: A0Lock.sharedLock())
A0Lock.sharedLock().registerAuthenticators([windowslive]);
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);
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: