I am using ADAL.js with an implicit stream to authenticate an AngularJS application to be able to access the Azure Mobile Services API.
I set the Azure AD identity on the Identity tab of AMS (Azure Mobile Service) as follows:
Application URL: https: // <> .azure-mobile.net / login / aad
Client ID is the client ID from the application installed on Azure AD.
Valid tenant: <>. onmicrosoft.com
The header is included in the GET request: Authorization: Media eyJ0eXAiOiJKV1Qi ...
But I get a 401 response from AMS.
What am I doing wrong or missing?
UPDATE: It looks like I will need to call the AMS endpoint by passing Azure AD access_token to get the AMS token. And I get this answer:
{"code": 401, "error": "Error: authentication with" windowsazureactivedirectory "is not supported." }
So, I assume that I will need to ask for support from the service specified by https://msdn.microsoft.com/en-us/library/azure/dn283952.aspx
Maybe someday this will be supported for the back of javascript. But the more I do AMS, the more it looks like I should have a .net backend.
UPDATE 05/29
I changed my AMS to a .Net server to use the client thread. I am using the following code:
client.login('aad', { "access_token": sessionStorage['adal.idtoken'] }) .done(function (results) { alert("You are now logged in as: " + results.userId); sessionStorage.X_ZUMO_AUTH = results.mobileServiceAuthenticationToken; }, function (err) { alert("Error: " + err); });
However, I get a 401 answer.
UPDATE: Based on another SO issue, I created a second application in Azure AD for the client. I installed it to access the API application. I also updated my code to the following:
adalService.acquireToken('<<AMS App Client ID>>') .then(function(token) { $http({ method: 'POST', url: constants.apiBaseUrl + '/login/aad', data: { "access_token" : token }, headers: { 'X-ZUMO-APPLICATION': constants.appKey } }). success(function (data, status, headers, config) { alert(data); }). error(function (data, status, headers, config) { alert(data); }); }); }
But I still get 401. I also tried it with mobile sdk, still 401.