Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
module.exports = function (authConfig) {
var opts = {}
opts.jwtFromRequest = ExtractJwt.fromUrlQueryParameter('jwt');
opts.secretOrKey = authConfig.secret;
return new JwtStrategy(opts, function(jwt_payload, done) {
done(null,jwt_payload.sub);
});
};
constructor(
private readonly authService: AuthService,
configService: ConfigService
) {
super({
jwtFromRequest: ExtractJwt.fromExtractors([
ExtractJwt.fromAuthHeaderAsBearerToken(),
ExtractJwt.fromUrlQueryParameter("access_token"),
req => {
const token = req.cookies && req.cookies.access_token;
return token;
}
]),
secretOrKey: configService.get("JWT_SECRET_KEY")
});
}
export default function(passport) {
passport.use(
new JwtStrategy(
{
jwtFromRequest: ExtractJwt.fromExtractors([
ExtractJwt.fromUrlQueryParameter("state"),
ExtractJwt.fromAuthHeaderAsBearerToken(),
]),
secretOrKey: jwtSecret,
},
(jwtPayload, done) => done(null, jwtPayload.user)
)
);
}
function getExtractor(extractor: string, param: string) {
switch(extractor) {
case 'header': return ExtractJwt.fromHeader(param);
case 'queryParam': return ExtractJwt.fromUrlQueryParameter(param);
case 'authHeader': return ExtractJwt.fromAuthHeaderWithScheme(param);
case 'bodyField': return ExtractJwt.fromBodyField(param);
case 'cookie': return (req)=>{
let token = null;
if (req && req.cookies)
{
token = req.cookies[param];
}
return token;
};
}
return ExtractJwt.fromAuthHeader();
}
constructor(
private readonly authService: AuthService,
configService: ConfigService
) {
super({
jwtFromRequest: ExtractJwt.fromExtractors([
ExtractJwt.fromAuthHeaderAsBearerToken(),
ExtractJwt.fromUrlQueryParameter("access_token"),
req => {
const token = req.cookies && req.cookies.access_token;
return token;
}
]),
secretOrKey: configService.get("JWT_SECRET_KEY")
});
}
constructor(
private readonly authService: AuthService,
configService: ConfigService,
) {
super({
jwtFromRequest: ExtractJwt.fromExtractors([
ExtractJwt.fromAuthHeaderAsBearerToken(),
ExtractJwt.fromUrlQueryParameter('access_token'),
(req) => {
const token = req.cookies && req.cookies.access_token;
return token;
},
]),
secretOrKey: configService.get('JWT_SECRET_KEY'),
});
}