我正在尝试使用 angular-jwtservice
但它没有在 http 调用上附加授权:
angular.module('TestApp')
.config(function Config($httpProvider, jwtInterceptorProvider) {
jwtInterceptorProvider.tokenGetter = ['merchantService', function(merchantService) {
merchantService.doSomething();
return localStorage.getItem('token');
}];
$httpProvider.interceptors.push('jwtInterceptor');
})
.service('Merchant', ['$http', function($http) {
var baseUrl = "http://test.com";
return {
terminal: function(success, error) {
$http.jsonp(baseUrl + '/tests?callback=jsonp_callback').success(success).error(error)
}
}
}]);