【问题标题】:angular-jwt no token in headerangular-jwt 标头中没有标记
【发布时间】:2017-02-16 14:35:50
【问题描述】:

我使用 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' }

我忘记或不明白什么?我需要在我的请求中手动传递标头吗?

【问题讨论】:

    标签: angularjs oauth jwt


    【解决方案1】:

    你没有正确定义 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;
      }
    });
    

    【讨论】:

      猜你喜欢
      • 2017-05-02
      • 2016-01-22
      • 2020-07-26
      • 1970-01-01
      • 2016-07-14
      • 2018-12-10
      • 2019-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多