javascript - AngularJS + ADAL.JS set Resource ID (Audience) -
how can use adal.js in angularjs bearer token audience https://management.azure.com javascript code?
i have created client application in ad , set permissions allow access "windows azure service management api". angularjs code follows:
adalservice.init( { instance: "https://login.windows.net/", tenant: "<something>.onmicrosoft.com", clientid: "<some id>", cachelocation: 'localstorage', redirecturi: 'http://localhost:63691/index.html#/configure', endpoints: { /* 'target endpoint called': 'target endpoint's resource id' */ 'https://management.azure.com/subscriptions?api-version=2014-04-01': 'https://management.azure.com/' } }, $httpprovider ); if use token received adalservice in postman call https://management.azure.com/subscriptions?api-version=2014-04-01, following error:
the access token has been obtained wrong audience or resource '<some id>'. should match (including forward slash) 1 of allowed audiences 'https://management.core.windows.net/','https://management.azure.com/'.
okay found solution after going through source code of adal.js here. @ line 137, looks @ config.loginresource see if has been set when passing config object init() function.
putting out there getting stuck:
if need token have claim “https://management.azure.com/” (or other resource uri), can set audience when initializing authenticationcontext so:
app.config(['$routeprovider', '$httpprovider', 'adalauthenticationserviceprovider', function ($routeprovider, $httpprovider, adalservice) { adalservice.init( { instance: "https://login.microsoftonline.com/", tenant: "<something>.onmicrosoft.com", clientid: "<client-id>", cachelocation: 'localstorage', //optional redirecturi: '<redirect-uri>', loginresource: 'https://management.azure.com/' //to set audience }, $httpprovider ); }]);
Comments
Post a Comment