【发布时间】:2016-03-10 07:03:26
【问题描述】:
我正在使用http-auth-interceptor 进行身份验证。在http-auth-interceptor中,我使用如下方式登录:
var data = 'username=' + encodeURIComponent(user.userId) + '&password=' + encodeURIComponent(user.password);
$http.post('api/authenticate', data, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
ignoreAuthModule: 'ignoreAuthModule'
})
ignoreAuthModule 用于告诉ignoreAuthModule 这个登录方法将被auth 拦截器忽略。
现在,我有一些关于 $resource 的请求,例如:
.factory('SomeDataService', function ($resource) {
return $resource('api/some/data', {}, {
'get': { method: 'GET'}
});
})
我希望SomeDataService.get() 也被身份验证拦截器忽略,因为我需要自己控制 401 错误。
所以,我的问题是,有什么方法可以让我在 $http 中设置类似的配置。
[根据评论更新]
我已经收听了login-required 事件:
$rootScope.$on('event:auth-loginRequired', function (rejection) {
$log.log(rejection);
// I need to get the request url and for some specific url, need to do something.
$rootScope.loginPopup();
});
但是“rejection”参数没有我需要的请求上下文数据。我需要获取请求 url 并检查,对于某些指定的 url,我需要做一些事情。
【问题讨论】:
-
您正在收听“event:auth-loginRequired”,对吧?为什么不在那里检查它的来源并采取相应的行动?
标签: angularjs angular-resource angular-http-auth