本文介绍了NodeJS-Passport-JWT,如何设置多个提取器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

这是我的身份验证策略的配置:

Here is the configuration of my authentication strategy :

var JWT_STRATEGY_CONFIG = {
  jwtFromRequest: ExtractJwt.fromAuthHeaderWithScheme('MyBearer'),
  secretOrKey: SECRET,
  issuer : ISSUER,
  audience: AUDIENCE,
  passReqToCallback: false
};

我想添加第二个提取器,如果第一个提取器失败,那么我想尝试第二个提取器.为了说明我的想法,这是我想做的事情:

I would like to add a second extractor, if the first one fail, then i'd like to try the second one. To illustrate my idea, here is what I'd like to do :

var JWT_STRATEGY_CONFIG = {
  jwtFromRequest: [
    ExtractJwt.fromAuthHeaderWithScheme('MyBearer'),
    ExtractJwt.fromUrlQueryParameter('authorization')
  ],
  secretOrKey: SECRET,
  issuer : ISSUER,
  audience: AUDIENCE,
  passReqToCallback: false
};

推荐答案

您还可以在ExtractJwt.fromExtractors函数中传递多个提取器

you can also pass multiple extractor in ExtractJwt.fromExtractors function

     var JWT_STRATEGY_CONFIG = {
      secretOrKey: SECRET,
      issuer : ISSUER,
      audience: AUDIENCE,
      passReqToCallback: false,
     jwtFromRequest:ExtractJwt.fromExtractors([ExtractJwt.fromBodyField('auth_token'),ExtractJwt.fromUrlQueryParameter('auth_token')]),

};

这篇关于NodeJS-Passport-JWT,如何设置多个提取器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 16:18