我使用angular-jwt angular-jwt": "^0.1.5"
,我检查文档但它不起作用。
这是在我的app.js
中,令牌已设置并获取:
.config(function Config($httpProvider, jwtOptionsProvider) {
$httpProvider.interceptors.push('jwtInterceptor');
jwtOptionsProvider.config({
whiteListedDomains: ['http://localhost:8080/', 'localhost'],
tokenGetter: function(options, jwtHelper) {
var token = window.localStorage.getItem('token');
return token;
}
});
})
我无法在我的请求中找到标题授权:
{ host: '172.18.17.155:8080',
connection: 'keep-alive',
accept: 'application/json, text/plain, */*',
origin: 'http://localhost:8100',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36',
referer: 'http://localhost:8100/',
'accept-encoding': 'gzip, deflate, sdch',
'accept-language': 'fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4' }
我忘了还是不明白?我需要手动在请求中传递标题吗?
答案 0 :(得分:2)
您没有正确定义whiteListedDomains,实际上您应该设置主机值属性:
例如:whiteListedDomains:['172.18.17.155']
.config(function Config($httpProvider, jwtOptionsProvider) {
$httpProvider.interceptors.push('jwtInterceptor');
jwtOptionsProvider.config({
whiteListedDomains: ['172.18.17.155'],
tokenGetter: function(options, jwtHelper) {
var token = window.localStorage.getItem('token');
return token;
}
});