How to use the jws.sign function in jws

To help you get started, we’ve selected a few jws 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 salrashid123 / gcpsamples / id_token / node / google-id-token.js View on Github external
fs.readFile(service_account_json, "utf-8",  async (err, data) => {
    var parsed_json = JSON.parse(data);

    const iat = Math.floor(new Date().getTime() / 1000);
    const exp = iat + 3600;  // 3600 seconds = 1 hour

    var payload = {
      iss: parsed_json.client_email,
      aud: "https://www.googleapis.com/oauth2/v4/token",
      exp: exp,
      iat: iat,
      target_audience: "https://yourapp.appspot.com/"
    }

    const signature = jws.sign({
      header:  {alg: 'RS256', typ: 'JWT', kid: parsed_json.private_key_id},
      payload:  payload,
      privateKey: parsed_json.private_key
    });

    console.log("*****************  Google Id Token *****************");
    console.log(signature);
    console.log("Exchanging JWT for Google ID Token");

    data = {
      'grant_type' : 'urn:ietf:params:oauth:grant-type:jwt-bearer',
      'assertion' : signature
    }

    var config = {
      headers : {"Content-type": "application/x-www-form-urlencoded"}
github strongloop / microgateway / lib / oauth2 / oauth2-helper.js View on Github external
function generateJWT(payload, secret, alg) {
  var body = {
    header: { alg: alg || 'HS256' }, // Default to hash
    secret: secret,
    payload: payload };
  return jwt.sign(body);
}
github mattfroese / vue-identity / examples / server.routes.js View on Github external
function token(user) {
  let now = (Date.now())/1000
  return jws.sign({
    header: { alg: 'HS256' },
    payload: {
      exp: now+60,
      iat: now,
      nbf: now-2,
      name: user
    },
    secret: secret,
  })
}
github AzureAD / passport-azure-ad / lib / jsonWebToken.js View on Github external
exports.generateClientAssertion = function(clientID, token_endpoint, privatePEMKey, thumbprint, callback) { 
  var header = { 'x5t': thumbprint, 'alg': 'RS256', 'typ': 'JWT' };
  var payload = {
    sub: clientID,
    iss: clientID,
    jti: Date.now() + aadutils.uid(16),
    nbf: Math.floor(Date.now()/1000),
    exp: Math.floor(Date.now()/1000) + CONSTANTS.CLIENT_ASSERTION_JWT_LIFETIME,
    aud: token_endpoint,
  };

  var clientAssertion;
  var exception = null;

  try {
    clientAssertion = jws.sign({
      header: header, 
      payload: payload, 
      privateKey: privatePEMKey
    }); 
  } catch (ex) {
    exception = ex;
  }

  callback(exception, clientAssertion); 
};
github teambition / snapper-core / bin / token.js View on Github external
function sign (payload, secretOrPrivateKey, options) {
  options = options || {}

  var header = {typ: 'JWT', alg: options.algorithm || 'HS256'}
  return jws.sign({header: header, payload: payload, secret: secretOrPrivateKey})
}
github elmadev / elmaonline-site / src / utils / auth.js View on Github external
getKuskiData(kuski, encryptedPassword).then(kuskiData => {
      if (kuskiData) {
        if (encryptedPassword === kuskiData.dataValues.Password) {
          const token = jws.sign({
            header: { alg: config.jwtAlgo },
            payload: {
              username: kuskiData.dataValues.Kuski,
              userid: kuskiData.dataValues.KuskiIndex,
            },
            secret: config.jwtSecret,
          });
          resolve({
            success: true,
            token,
            username: kuskiData.dataValues.Kuski,
            userid: kuskiData.dataValues.KuskiIndex,
          });
        } else {
          resolve({
            success: false,
github irislib / iris-lib / message.js View on Github external
sign: function(msg, privKeyPEM, hex, skipValidation) {
    if (!skipValidation) {
      validate(msg);
    }
    msg.jwsHeader = { alg: 'ES256', kid: hex };
    msg.jws = jws.sign({
      header: msg.jwsHeader,
      payload: msg.signedData,
      privateKey: privKeyPEM
    });
    if (!skipValidation) {
      validateJws(msg);
    }
    msg.hash = getHash(msg).toString(encoding);
    return msg.jws;
  },
github googleapis / node-gtoken / lib / index.js View on Github external
GoogleToken.prototype._signJWT = function(opts, callback) {
  try {
    var signedJWT = jws.sign(opts);
    return callback(null, signedJWT);
  } catch (err) {
    callback(err, null);
  }
};

jws

Implementation of JSON Web Signatures

MIT
Latest version published 5 years ago

Package Health Score

74 / 100
Full package analysis