How to use the express-jwt.decode function in express-jwt

To help you get started, we’ve selected a few express-jwt 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 steedos / object-server / packages / auth / src / jwt.ts View on Github external
router.get('/jwt/sso', async function (req, res) {
  try {
    let jwt = require('jsonwebtoken');
    let token = req.query.jwt_token;
    if (!token) {
      throw new Error('jwt_token is needed!')
    }
    let decoded = jwt.decode(token, { complete: true });
    let payload = decoded.payload;
    let issuer = payload.iss;
    if (!issuer) {
      throw new Error('issuer is needed!')
    }
    let collection = getSteedosSchema().getObject('OAuth2Clients')
    let clients = await collection.find({ filters: `clientId eq '${issuer}'` })
    let clientInfo = clients[0]
    let secret = clientInfo ? clientInfo.clientSecret : ''
    if (!secret) {
      throw new Error('secret is needed!')
    }
    let verifiedPayload = jwt.verify(token, secret);
    let data = await getTokenInfo({ user: verifiedPayload })
    res.cookie('X-User-Id', data.userId, { maxAge: 90 * 60 * 60 * 24 * 1000, httpOnly: true });
    res.cookie('X-Auth-Token', data.authToken, { maxAge: 90 * 60 * 60 * 24 * 1000, httpOnly: true });

express-jwt

JWT authentication middleware.

MIT
Latest version published 2 years ago

Package Health Score

64 / 100
Full package analysis