本文整理匯總了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'),
});
}
示例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
});
});
示例3: constructor
constructor(private readonly authService: AuthService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: 'secretKey',
algorithms: 'HS512'
});
}
示例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);
}
示例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);
}
示例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);
}
});
}
示例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) => {
示例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));
}
示例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;
示例10: constructor
constructor(private readonly authservice: AuthService) {
super({
jwtFromrequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: configService.getString("SECRET_KEY")
});
}