我在我的angular js应用程序中使用AdalJs,当我访问外部API时,adal拦截器检查会话存储中是否存在我的资源,如果会话存储中不存在则获取令牌调用。检索到令牌后,它会使用该资源的新令牌更新会话存储,但控件不会返回到ajax调用,并且调用者会卡在那里。如果我再次刷新页面,我就可以获取数据来自永恒的API,因为它现在能够从会话存储中获取数据。我在这里错过了什么吗?
sampleApp.config(['$routeProvider', '$httpProvider', 'config', 'adalAuthenticationServiceProvider', function ($routeProvider, $httpProvider, config, adalProvider) {
$routeProvider
// route for the home page
.when('/home', {
templateUrl : 'pages/home.html',
controller : 'mainController',
})
.when('/userInfo', {
templateUrl : 'pages/userInfo.html',
controller : 'userInfoController',
requireADLogin: true,
})
.when('/apiData', {
templateUrl : 'pages/apiData.html',
controller : 'apiDataController',
requireADLogin: true,
}).otherwise({ redirectTo: "/home" });
adalProvider.init({
instance: config.instance,
tenant: config.tenant, //adfs
clientId: config.clientId,
extraQueryParameter: config.extraQueryParameter,
endpoints : config.endpoints,
redirectUri : config.redirectUri,
},
$httpProvider);
}]);
sampleApp.controller('apiDataController', function($scope, adalAuthenticationService, $http, config) {
$scope.message = 'Fetching data from the API:';
$scope.userInfo = adalAuthenticationService.userInfo;
var client = $http({
method: 'GET',
url: config.apiURL,
headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }
});
client.then(function(data){
console.log(data);
$scope.message = "Data is fetched from the API with Access Token";
$scope.apiData = data.data;
}, function(data) {
console.log(data)
$scope.message = data.data;
});
});
答案 0 :(得分:0)
您的代码是正确的,当我们将Azure AD集成到AngularJS单页面应用程序中时,我们需要确保adal.js和Angular.js版本相同,版本不匹配可能会导致潜在问题。