angularjs - Make API call to Azure API App in JavaScript with Active Directory authentication -


i implemented java api backend hosted in azure api app. switched on authentication active directory. in cors settings of api app configured allowing calls every source settings asterisk url.

now want access api local angularjs app. angular code looks this:

angular.module('demo', [])     .controller('getdatacontroller', function($scope, $http) {         $scope.login = function(user){             console.log("user: " + user, user);              $http.defaults.usexdomain = true;             delete $http.defaults.headers.common['x-requested-with'];              $http.get('http://<myapiapp>.azurewebsites.net/api/contacts').             then(function(response) {                 $scope.greeting = response.data;                 console.log("$scope.greeting: " + $scope.greeting, $scope.greeting);             });         }     }); 

but still receive following error within console:

xmlhttprequest cannot load https://login.windows.net/ 12141bed-36f0-4fc6-b70c-43483f616eb7/oauth2/autho… %2fapi%2fcontacts%23&nonce=ea6b31321cda45d6a4e881fbd0062974_20161026094547. redirect 'https://login.windows.net/12141bed-36f0-4fc6-b70c-43483f616eb7/ oauth2/autho…%2fapi%2fcontacts%23& nonce=ea6b31321cda45d6a4e881fbd0062974_20161026094547'  'https://login.microsoftonline.com/12141bed-36f0-4fc6-b70c-43483f616eb7/ oaut…%2fapi%2fcontacts%23&nonce=ea6b31321cda45d6a4e881fbd0062974_20161026094547'  has been blocked cors policy: no 'access-control-allow-origin' header present on requested resource.  origin 'null' therefore not allowed access. 

so how access angularjs code?

this related post here try access curl call.

it seems generating http requests directly web apps protected azure ad. scenario, can try implement adal js in angularjs client. leveraging adal gain authentication token, , when call web apps in angular, add authentication header in http requests.

any further concern, please feel free let me know.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -