Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Signature verification failed #100

Open
codefaztaz opened this issue Nov 3, 2020 · 0 comments
Open

Error: Signature verification failed #100

codefaztaz opened this issue Nov 3, 2020 · 0 comments

Comments

@codefaztaz
Copy link

I have an error signature verification failed

'use strict'

// const jwt = require('jsonwebtoken');
// const fs = require('fs');
var jwt = require('jwt-simple');
var moment = require('moment');
var secret = 'MIIEpAIBAAKCAQEAyVTQ9QxfutaYXKBbYfZbH2vhIWoIPEjAFSbsy1PZoIcclUQRhJ8t2m7v47M8eEyYd7EvXTNdoN6CDs0DoNC9KESATZV5SUVr7sk9pOcMrm0VryAdh7hQbbHWqyKmOehCt1JdX7gV2i5XnRb5qYQSyoB8sGdfR4SQ9q1XPRIpBP8RYXCP';

exports.authenticated = function(req, res, next) {

// Comprobar si llega autorización
if (!req.headers.authorization) {
    return res.status(403).send({
        message: 'La petición no tiene la cabecera de authorization'
    });
}

// Limpiar el token y quitar comillas
var token = req.headers.authorization.replace(/['"]+/g, '');


console.log(token);
console.log(secret);
var payload = jwt.decode(token, secret);

try {
    // Decodificar token
    var payload = jwt.decode(token, secret, false, 'HS256');
    console.log(payload);
    // Adjuntar usuario identificado a request
    // req.user = payload;

    // Pasar a la acción
    //   next();

    // Comprobar si el token ha expirado
    if (payload.exp <= moment(15 * 60).unix()) {
        return res.status(404).send({
            message: 'El token ha expirado'
        });
    }

} catch (ex) {
    return res.status(404).send({
        message: 'El token no es válido'
    });
}

// Adjuntar usuario identificado a request
req.user = payload;

// Pasar a la acción
next();

};

I dont know how to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant