I am trying to authenticate an HTML application on an Azure Mobile Service application.
Customization
Both applications use AAD as authentication, so both applications have an application registered in Active Directory:
Azure Mobile Service App:
HTML application:
- in "permissions for other applications" I added an Azure Mobile Service application with delegated permission "access"
The Azure Mobile Service uses the .NET backend, in which I have included and configured the NuGet package "Microsoft Backup Security Extension for Microsoft Azure Mobile Services.NET", as described in https://azure.microsoft.com/en-gb/documentation/articles / mobile-services-dotnet-backend-windows-phone-get-started-users /
The HTML application uses ADAL.JS and Angular:
adalAuthenticationServiceProvider.init( { // Config to specify endpoints and similar for your app clientId: "<html app aad client id>", redirectUri: "<html app redirect uri>", endpoints: { '<AMS app client id>': 'https://ampapp.azure-mobile.net/' } }, $httpProvider );
This setup works as expected, I open the html application, authenticate against Azure AD, get a redirect to my application, and I am logged in. Also, when I try to access my Azure Mobile Service, I see that Adal.js enters the media token.
Problem
The carrier token is not accepted by the Azure Mobile Service - I receive 401 not authorized. I donβt know why, but the Azure Mobile Service uses its own authentication header, but good.
MSDN defines the so-called "client login operation" for Azure Mobile Service:
"Requires an authentication token from Microsoft Azure Mobile Services, using an authentication token already obtained from the identity provider." ( https://msdn.microsoft.com/en-us/library/azure/jj710106.aspx )
So let's do the following:
// obtain token for Azure Mobile Service from Adal.js var token = this.getAADToken(ZUMOAuthenticationProvider.Config().url); $http({ method: 'POST', url: ZUMOAuthenticationProvider.Config().url + 'login/aad', data: JSON.stringify({ "access_token" : token }), headers: { 'X-ZUMO-APPLICATION': '<application key>' }). success(function (data, status, headers, config) { alert(data); }). error(function (data, status, headers, config) { alert(data); });
Note. The token received on the first line is indeed an access token for the azure app for aad mobile apps, not the HTML app.
This POST request also receives a 401 response. Therefore, I do not know how to authenticate my application. I also tried azure mobile service js lib. This library works, but it uses a popup for authentication, but I don't like adding another library to my projects for just a few REST calls.
Similar problems
While trying to solve my problems, I found another Stackoverflow entry:
Why is my Azure Mobile Service not accepting the carrier token that ADAL.js sends?
- same problem, no solution (even in chat related in last comment)
How to secure Azure Mobile Service with Azure AD? ADAL.JS
- the same author as above, I checked everything that is mentioned in the accepted answer, but it does not work.
I also reviewed new Azure Mobile apps from the new Azure Management portal, but it looks like they use the same authentication mechanism.
So how can I make this work?