當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript passport-jwt.ExtractJwt類代碼示例

本文整理匯總了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;未經允許,請勿轉載。