• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript passport-jwt.ExtractJwt类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中passport-jwt.ExtractJwt的典型用法代码示例。如果您正苦于以下问题:TypeScript ExtractJwt类的具体用法?TypeScript ExtractJwt怎么用?TypeScript ExtractJwt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ExtractJwt类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: before

    before((done) => {
        const app = express();

        passport.use(new JwtStrategy({
            jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
            secretOrKey: JWT_SECRET
        }, (payload: any, done: VerifiedCallback) => {
            done(null, payload.name);
        }));

        app.use(passport.initialize());
        app.use(passport.authenticate('jwt', { session: false }));

        app.get('/', (req, res) => {
            res.send('hello world! ' + req.user);
        });

        server = app.listen(3000, () => {
            done();
        });

        client = axios.create({
            baseURL: 'http://localhost:3000',
            validateStatus: status => true
        });
    });
开发者ID:loki2302,项目名称:nodejs-experiment,代码行数:26,代码来源:passport-jwt.spec.ts


示例2: constructor

 constructor(private readonly authService: AuthService) {
   super({
     jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
     secretOrKey: 'secretKey',
     algorithms: 'HS512'
   });
 }
开发者ID:echolaw,项目名称:work-day,代码行数:7,代码来源:jwt.strategy.ts


示例3: config

    config() {

        let opts = {
            secretOrKey: config.secret,
            jwtFromRequest: ExtractJwt.fromAuthHeaderWithScheme('bearer')
        };

        passport.use(new Strategy(opts, (jwtPayload, done) => {
            User
                .getById(jwtPayload.id)
                .then(user => {
                    if (user) {
                        return done(null, {
                            id: user.id,
                            email: user.email
                        });
                    }
                    return done(null, false);
                })
                .catch(error => {
                    done(error, null);
                })
        }));

        return {
            initialize: () => passport.initialize(),
            authenticate: () => passport.authenticate('jwt', { session: false })
        }
    }
开发者ID:mromanjr93,项目名称:nodejsddd,代码行数:29,代码来源:auth.ts


示例4: constructor

 constructor(private readonly authService: AuthService,
             private readonly config: ConfigService) {
   super({
     jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
     secretOrKey: config.get('JWT_KEY'),
   });
 }
开发者ID:InsaneWookie,项目名称:mame-highscores,代码行数:7,代码来源:jwt.strategy.ts


示例5: constructor

 constructor(private readonly authService: AuthService) {
   super(
     {
       jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
       passReqToCallback: true,
       secretOrKey: process.env.JWT_SECRET,
     },
     async (req, payload, next) => await this.verify(req, payload, next)
   );
   passport.use(this);
 }
开发者ID:hyperaudio,项目名称:ha-api,代码行数:11,代码来源:jwt.strategy.ts


示例6: constructor

 constructor(private readonly authService: AuthService) {
     super({
         //用來帶入驗證的函式
         jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
         //設成true就可以在verify的callback中使用 
         passReqToCallback: true,
         secretOrKey: 'donttalk',
     },
         async (req, payload, next) => await this.verify(req, payload, next)
     );
     passport.use(this);
 }
开发者ID:fanybook,项目名称:Nestjs30Days,代码行数:12,代码来源:jwt.strategy.ts


示例7: function

function (model: DatabaseObject, passport: Passport): void {
  let opts: any = {}
  opts.secretOrKey = model.tokenSalt
  opts.jwtFromRequest = ExtractJwt.fromHeader('token')

  let strategy = new Strategy(opts, (jwtPayload, done) => {
    model.user.findOne({ _id: jwtPayload._doc._id }).exec()
    .then((account) => {
      account === undefined ? done(undefined, false) : done(undefined, account)
    }, (err) => {
      done(err, false)
    })
  })

  passport.use(strategy)
}
开发者ID:chipp972,项目名称:stock_manager_api,代码行数:16,代码来源:auth.ts


示例8: init

 static init():void {
   var JwtStrategy = require('passport-jwt').Strategy,
   ExtractJwt = require('passport-jwt').ExtractJwt;
   var opts = {}
   opts.jwtFromRequest = ExtractJwt.fromAuthHeader();
   opts.secretOrKey = DBConfig.secret;
   passport.use(new JwtStrategy(opts, function(jwt_payload, done) {
     User.findOne({id: jwt_payload.sub}, function(err, user) {
         if (err) {
             return done(err, false);
         }
         if (user) {
             done(null, user);
         } else {
             done(null, false);
             // or you could create a new account 
         }
     });
 }));
 }
开发者ID:ericmdantas,项目名称:Gen-App,代码行数:20,代码来源:passport.ts


示例9: setupJwt

function setupJwt(kind: string): passport.Strategy {
    const JWTStrategy = passportJWT.Strategy;
    const ExtractJwt = require("passport-jwt").ExtractJwt;
    var opts = {
        jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
        secretOrKey: config.get(`security.secrets.${kind.toUpperCase()}`),
        passReqToCallback: true
    };
    return new JWTStrategy(opts, async (req: any, jwt_payload: IPayload, next: any) => {
        logger.debug("payload received", jwt_payload);
        // usually this would be a database call:
        const user: IUser = await UserDB.getByToken(kind, jwt_payload);
        if (user) {
            (user as any).usedStrategy = kind;
            next(null, user);
        } else {
            next(null, false);
        }
    });
}
开发者ID:ZulusK,项目名称:Budgetarium,代码行数:20,代码来源:auth.ts


示例10: done

                        if (equal) {
                            return done(null, user);
                        } else {
                            return done(err, false, { message: 'Failed to authenticate.' });
                        }
                    });
            } else {
                return done(err, false, { message: 'Failed to authenticate.' });
            }
        });
    });
passport.use(strategy);

let jwtOptions: jwt.StrategyOptions = {
    secretOrKey: 'qwerty',
    jwtFromRequest: jwt.ExtractJwt.fromAuthHeaderWithScheme('jwt')
};
let jwtStrategy = new jwt.Strategy(
    jwtOptions,
    (payload, done) => {
        let db = new UserRepository();
        db.findById(payload.userId, (err, user) => {
            if (err) {
                done(err, false);
            } else {
                if (user) {
                    done(null, user);
                } else {
                    done(null, false);
                }
            }
开发者ID:kmarecki,项目名称:slovo,代码行数:31,代码来源:auth.ts



注:本文中的passport-jwt.ExtractJwt类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript passport-oauth2.VerifyCallback类代码示例发布时间:2022-05-25
下一篇:
TypeScript passport.Passport类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap