当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ExtractJwt.fromAuthHeaderAsBearerToken方法代码示例

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


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

示例1: 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

示例2: 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

示例3: constructor

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

示例4: 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

示例5: 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

示例6: 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

示例7: expect

            request.put('http://localhost:5674/authorization/methods/profile', {
                headers: {
                    'Authorization': `Bearer ${generateJwt()}`
                }
            }, (error, response, body) => {
                expect(response.statusCode).to.eq(403);
                done();
            });
        });
    });
});

const JWT_SECRET: string = 'some-jwt-secret';

const jwtConfig: StrategyOptions = {
    jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
    secretOrKey: Buffer.from(JWT_SECRET, 'base64'),
};

interface JwtUser {
    username: string;
    roles: Array<string>;
}

interface JwtUserPayload {
    sub: string;
    auth: string;
}

function configureAuthenticator() {
    const strategy = new Strategy(jwtConfig, (payload: JwtUserPayload, done: (a: null, b: JwtUser) => void) => {
开发者ID:thiagobustamante,项目名称:typescript-rest,代码行数:31,代码来源:authenticator.spec.ts

示例8: constructor

 constructor(private readonly authService: AuthService, config: Config) {
   super({
     jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
     secretOrKey: config.get('SECRET'),
   }, async (payload: JwtPayload, next: Function) => await this.validate(payload, next));
 }
开发者ID:OysteinAmundsen,项目名称:gymsystems,代码行数:6,代码来源:jwt.strategy.ts

示例9: JwtStrategy

    jwtFromRequest: ExtractJwt.fromAuthHeader(),
    secretOrKey: 'secret',
    issuer: "accounts.example.com",
    audience: "example.org"
};

passport.use(new JwtStrategy(opts, function(jwt_payload, done) {
    findUser({id: jwt_payload.sub}, function(err, user) {
        if (err) {
            return done(err, false);
        }
        if (user) {
            done(null, user);
        } else {
            done(null, false, {message: 'foo'});
            // or you could create a new account
        }
    });
}));

opts.jwtFromRequest = ExtractJwt.fromHeader('x-api-key');
opts.jwtFromRequest = ExtractJwt.fromBodyField('field_name');
opts.jwtFromRequest = ExtractJwt.fromUrlQueryParameter('param_name');
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderWithScheme('param_name');
opts.jwtFromRequest = ExtractJwt.fromExtractors([ExtractJwt.fromHeader('x-api-key'), ExtractJwt.fromBodyField('field_name'), ExtractJwt.fromUrlQueryParameter('param_name')]);
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
opts.jwtFromRequest = (req: Request) => { return req.query.token; };
opts.secretOrKey = new Buffer('secret');

declare function findUser(condition: {id: string}, callback: (error: any, user :any) => void): void;
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:30,代码来源:passport-jwt-tests.ts

示例10: constructor

 constructor(private readonly authservice: AuthService) {
   super({
     jwtFromrequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
     secretOrKey: configService.getString("SECRET_KEY")
   });
 }
开发者ID:jonathan-patalano,项目名称:blog-api,代码行数:6,代码来源:jwt.strategy.ts


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