How to use the jwt-simple.encode function in jwt-simple

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 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 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 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);
      });
    });
github PacktPublishing / Node.js_Design_Patterns_Second_Edition_Code / ch07 / 03a_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);
      });
    });
github PacktPublishing / Node.js_Design_Patterns_Second_Edition_Code / ch07 / 02_di / 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);
      });
    });
github cosmojs / universal / server / loopback-satellizer.js View on Github external
function createToken (user) {
  var payload = {
    sub: user.id,
    iat: moment().unix(),
    exp: moment().add(14, 'days').unix()
  };
  return jwt.encode(payload, config.TOKEN_SECRET);
}

jwt-simple

JWT(JSON Web Token) encode and decode module

MIT
Latest version published 5 years ago

Package Health Score

56 / 100
Full package analysis

Popular jwt-simple functions