(async () => { // create Gladys object const gladys = Gladys({ jwtSecret: process.env.JWT_SECRET, }); // start Gladys await gladys.start(); // start server server.start(gladys, SERVER_PORT, { serveFront: SERVE_FRONT, }); })();
jwt.verify(socket.handshake.query.token, process.env.JWT_SECRET, function( err, decoded ) { socket.user = decoded next() })
passport.use( new JwtStrategy( { secretOrKey: process.env.JWT_SECRET, jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken() }, (jwt_payload, cb) => { return cb(null, jwt_payload) } ) )
jwt.verify( token, process.env.JWT_SECRET || _.get(strapi.plugins['users-permissions'], 'config.jwtSecret') || 'oursecret', {}, function (err, tokenPayload = {}) { if (err) { return reject(new Error('Invalid token.')); } resolve(tokenPayload); } );
const createToken = id => { return jwt.sign({ id }, process.env.JWT_SECRET, { expiresIn: process.env.JWT_EXPIRES_IN }); }
jwt.verify(bearerToken, process.env.JWT_SECRET, (error, authData) => { // if valid, continue if (!error) return next(); // if not, send forbidden sendForbidden(res); });
jwt.sign(claims, process.env.JWT_SECRET, function(err, token){ if (err) reject(err); resolve(token); });
jwt.verify(token, process.env.JWT_SECRET, function(err, decoded){ if (err) { console.error('JWT error: '+err.message); reject(new Error('auth.error')); } // console.log("Token verified: "+JSON.Stringify(decoded)); resolve(decoded); })
const jwtSignUser = user => { try { const ONE_WEEK = 60 * 60 * 24 * 7; return jwt.sign(user, process.env.JWT_SECRET, { expiresIn: ONE_WEEK }); } catch (err) { console.log(err); } }
// get the user info from a JWT const getUser = token => { if (token) { try { // return the user information from the token return jwt.verify(token, process.env.JWT_SECRET); } catch (err) { // if there's a problem with the token, throw an error throw new Error('Session invalid'); } } }
// create signed JWT async function sign(uid) { return await jwt.sign({ uid }, process.env.JWT_SECRET); }
(async () => { // create Gladys object const gladys = Gladys({ jwtSecret: process.env.JWT_SECRET, }); // start Gladys await gladys.start(); // start server server.start(gladys, SERVER_PORT, { serveFront: SERVE_FRONT, }); })();
// get the user info from a JWT const getUser = token => { if (token) { try { // return the user information from the token return jwt.verify(token, process.env.JWT_SECRET); } catch (err) { // if there's a problem with the token, throw an error throw new Error('Session invalid'); } } }
// get the user info from a JWT const getUser = token => { if (token) { try { // return the user information from the token return jwt.verify(token, process.env.JWT_SECRET); } catch (err) { // if there's a problem with the token, throw an error throw new Error('Session invalid'); } } }
// get the user info from a JWT const getUser = token => { if (token) { try { // return the user information from the token return jwt.verify(token, process.env.JWT_SECRET); } catch (err) { // if there's a problem with the token, throw an error throw new Error('Session invalid'); } } }