JsonWebTokenError:必须提供 jwt
Posted
技术标签:
【中文标题】JsonWebTokenError:必须提供 jwt【英文标题】:JsonWebTokenError: jwt must be provided 【发布时间】:2020-11-26 05:04:21 【问题描述】:我使用 jwt 来确认电子邮件,我用带有令牌的 URL 向用户发送电子邮件,这是接收用户的 URL 示例:
的http://本地主机:3000 / firstlogin acces_token = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InJleWVzZUBncnVwb2ludmVyby5jb20iLCJpYXQiOjE1OTY2Njk4OTcsImV4cCI6MTU5Njc1NjI5N30.dt-qr8h40QfPMOq-DQDfQVHatrAqOubKdlUbV4-nsTw P>
我正在使用一个查询,你怎么能看到。
确认码是下一个:
const expressJwt = require('express-jwt')
const _ =require('lodash')
const OAuth2Client = require('google-auth-library')
const fetch = require('node-fetch')
const validationResult = require('express-validator')
const jwt = require('jsonwebtoken')
//Esto es para obtener el error de la base de datos, se puede personalizar para hacerlo amigable.
const errorHandler =require('../helpers/dbErrorHandling')
//el siguiente const se usará para enviar correos
const sgMail = require('@sendgrid/mail')
sgMail.setApiKey(process.env.MAIL_KEY)
const pool = require('../database/connection')
class FirstloginController
async getToken(req, res, next)
const token = (req.params.token);
const access_token = req.query;
try
const decoded = jwt.verify(access_token, process.env.JWT_ACCOUNT_ACTIVATION)
res.json( message: "El acces token es valido", email: decoded)
catch (err)
next(err);
const firstloginController = new FirstloginController();
module.exports = firstloginController;
请求是一个获取类型,它给我带来了下一个(在邮递员上):
<pre>JsonWebTokenError: jwt must be provided<br> &nbsp; &nbsp;at Object.module.exports [as verify] (C:\xampp\htdocs\seth\api\node_modules\jsonwebtoken\verify.js:53:17)<br> &nbsp; &nbsp;at getToken (C:\xampp\htdocs\seth\api\src\controllers\Firstlogin.controller.js:24:33)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (C:\xampp\htdocs\seth\api\node_modules\express\lib\router\layer.js:95:5)<br> &nbsp; &nbsp;at next (C:\xampp\htdocs\seth\api\node_modules\express\lib\router\route.js:137:13)<br> &nbsp; &nbsp;at Route.dispatch (C:\xampp\htdocs\seth\api\node_modules\express\lib\router\route.js:112:3)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (C:\xampp\htdocs\seth\api\node_modules\express\lib\router\layer.js:95:5)<br> &nbsp; &nbsp;at C:\xampp\htdocs\seth\api\node_modules\express\lib\router\index.js:281:22<br> &nbsp; &nbsp;at Function.process_params (C:\xampp\htdocs\seth\api\node_modules\express\lib\router\index.js:335:12)<br> &nbsp; &nbsp;at next (C:\xampp\htdocs\seth\api\node_modules\express\lib\router\index.js:275:10)<br> &nbsp; &nbsp;at Function.handle (C:\xampp\htdocs\seth\api\node_modules\express\lib\router\index.js:174:3)
我不知道这意味着什么;终端显示下一个:
GET /firstlogin?acces_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InJleWVzZUBncnVwb2ludmVyby5jb20iLCJpYXQiOjE1OTY2Njk4OTcsImV4cCI6MTU5Njc1NjI5N30.dt-qr8h40QfPMOq-DQDfQVHatrAqOubKdlUbV4-nsTw 500 5.011 ms - 1275
JsonWebTokenError: jwt must be provided
at Object.module.exports [as verify] (C:\xampp\htdocs\seth\api\node_modules\jsonwebtoken\verify.js:53:17)
at getToken (C:\xampp\htdocs\seth\api\src\controllers\Firstlogin.controller.js:24:33)
at Layer.handle [as handle_request] (C:\xampp\htdocs\seth\api\node_modules\express\lib\router\layer.js:95:5)
at next (C:\xampp\htdocs\seth\api\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\xampp\htdocs\seth\api\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\xampp\htdocs\seth\api\node_modules\express\lib\router\layer.js:95:5)
at C:\xampp\htdocs\seth\api\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\xampp\htdocs\seth\api\node_modules\express\lib\router\index.js:335:12)
at next (C:\xampp\htdocs\seth\api\node_modules\express\lib\router\index.js:275:10)
at Function.handle (C:\xampp\htdocs\seth\api\node_modules\express\lib\router\index.js:174:3)
我知道的基本就这些了,这个过程和发送邮件的过程在不同的文档中
【问题讨论】:
我遇到了同样的问题,请检查您的token字段是否正确 【参考方案1】:你写错了acces_token的拼写
使用
const access_token = req.query;
【讨论】:
以上是关于JsonWebTokenError:必须提供 jwt的主要内容,如果未能解决你的问题,请参考以下文章
JWT 给 JsonWebTokenError “无效令牌”
JSONWebTokenError:JWT 在 index.js 处格式错误
JsonWebTokenError: jwt malformed: can't verify my Webtoken