當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。