How to use jwt-simple - 10 common examples

To help you get started, we’ve selected a few jwt-simple examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TrainingByPackt / Professional-JavaScript / Lesson04 / Example / mongo_logger_middleware / routes / check-in.js View on Github external
(req, res) => {

    // If errors return 422, client didn't provide required values
    const errors = validationResult(req);
    if (!errors.isEmpty()) {
      return res.status(422).json({ errors: errors.array() });
    }

    // Otherwise use the server secret to encode the user's request as a JWT
    let info = {};
    info.token = jwt.encode(req.body, secret);
    res.json(info);
});
github YouTransfer / YouTransfer / lib / passport.js View on Github external
youtransfer.settings.get(function(err, settings) {

			var security = settings.security || {};
			var salt = security.encryptionKey || '';
			var user = jwt.decode(token, salt);

			// Check for JWT expiration
			var expires = new Date(user.exp);
			if(Date.compare(expires, new Date()) < 0) {
				user = null;
			}

			done(null, user);

		});
github huahua0406 / vue-authorization-login / server / app.js View on Github external
function createToken(openid,nickname) {
    const tokenExpiresTime = 1000 * 60 * 60 * 24 * 7 // 7天过期时间
    const JWT_SECRET = 'weixin_token' // 秘钥
    // 需要加密的对象
    const payload = {
        openid: openid,
        username:nickname,
        environment: 'web',
        expires: Date.now() + tokenExpiresTime
    }
    // encode
    const token = jwt.encode(payload, JWT_SECRET)
    return token
}
github PebbleFrame / item-chimp / server / db / db.js View on Github external
bcrypt.compare(candidatePassword, savedPassword, function (err, isMatch) {
            if (isMatch) {
	            token = jwt.encode(user.get('username'), 'secret');
	            db.emit('userLogin', {
		            token: token,
		            username: user.get('username'),
		            email: user.get('email')
	            });
            }
            else {
              token = undefined;
              console.log("Password Incorrect");
              db.emit('userLogin', token);
             }
          });
      }else{
github marley-nodejs / Two-Tier-Enterprise-App-and-API-Development-with-Angular-and-Sails / socialfleet / backend / api / policies / jwtAuth.js View on Github external
module.exports = function(req, res, next){
    if(!req.headers.authorization){
        return handleError();
    }

    var token = req.headers.authorization.split(' ')[1];

    var payload = jwt.decode(token, config.TOKEN_SECRET);

    if(!payload.sub){
        return handleError();
    }

    req.userId = payload.sub;
    next();
};
github nimblecode / nimblecode / server / controllers / userController.js View on Github external
bcrypt.compare(password, found.get('password'), function(err, result) {
          if(result) {
            console.log("HELLO!", result);
            var token = jwt.encode({username: username}, secret);
            validObj.token = token;
            validObj.isValid = true;
            validObj.username = username;
            res.send(validObj);
          } else {
            validObj.passwordFailed = true;
            res.send(validObj);
          }
        });
      } else {
github twilio / twilio-node / spec / task_router_capability_deprecated.spec.js View on Github external
it('should allow construction of a capability token', function() {
        var c = new twilio.TaskRouterCapability('AC123', 'foobar', 'WS456', 'WK789');
        var token = c.generate();

        var decoded = jwt.decode(token, 'foobar');
        expect(decoded).toBeDefined();
        expect(decoded['iss']).toBe('AC123');
        expect(decoded['account_sid']).toBe('AC123');
        expect(decoded['channel']).toBe('WK789');
        expect(decoded['workspace_sid']).toBe('WS456');
        expect(decoded['worker_sid']).toBe('WK789');
        expect(decoded['version']).toBe('v1');
        expect(decoded['exp']).toEqual(Math.floor(new Date() / 1000) + 3600);
    });
github Azure / kubernetes-hackfest / app-experimental / auth-api / routes / auth.js View on Github external
function createJWT(uid) {
  var payload = {
    sub: uid,
    iat: moment().unix(),
    exp: moment()
      .add(14, 'days')
      .unix()
  };
  console.log(payload);
  return jwt.encode(payload, TOKEN_SECRET);
}
github wisnuc / appifi / src / Fruitmix.js View on Github external
getToken (user) {
    return {
      type: 'JWT',
      token: jwt.encode({ uuid: user.uuid }, secret)
    }
  }
github PacktPublishing / Node.js_Design_Patterns_Second_Edition_Code / ch07 / 06_plugin_service_locator / lib / authService.js View on Github external
bcrypt.compare(password, user.hash, (err, res) => {
        if (err) return callback(err);
        if (!res) return callback(new Error('Invalid password'));
        
        const token = jwt.encode({
          username: username,
          expire: Date.now() + (1000 * 60 * 60) //1 hour
        }, tokenSecret);
        
        callback(null, token);
      });
    });

jwt-simple

JWT(JSON Web Token) encode and decode module

MIT
Latest version published 6 years ago

Package Health Score

56 / 100
Full package analysis

Popular jwt-simple functions