当请求一个瓶罐路由的请求时,需要使用(在瓶瓶资源上的@jwt_required
装饰器)访问JWT,我收到一条422 UNPROCESSABLE ENTITY
并显示消息:The specified alg value is not allowed
。
登录并导航到调用该请求的(前端)路由时:
this.axios.get("/jobs").then(res => {
console.log(res.data);
this.jobs = res.data.jobs;
});
同样可以正常运行,但是刷新后会显示422错误。 我将令牌存储在localstorage中,并将其加载到axios标头中,如下所示:
const api = {
init: function() {
Vue.use(VueAxios, axios);
Vue.axios.defaults.baseURL = DEV_URL;
},
setHeader: function() {
const token = `Bearer ${getToken()}`;
Vue.axios.defaults.headers.common["Authorization"] = token;
},
};
并在我的init()
中调用setHeader()
和main.js
,所以我很困惑为什么这仅在刷新后才导致错误。
关于如何解决The specified alg value is not allowed
错误,我找不到任何资源。任何援助将不胜感激! :)
答案 0 :(得分:1)
当在我的spring boot auth服务中创建JWT令牌时遇到了相同的问题,但是资源服务是Flask Micro服务。我尝试了以下步骤进行整理,
{
"alg": "HS512"
}
app.config['JWT_ALGORITHM'] = 'HS512'
之后,错误消息消失了,我能够从解码的令牌中解析信息。因此,您需要找到生成令牌的算法,并在烧瓶app.config
中设置适当的算法。
答案 1 :(得分:0)
如果令牌是使用不同于app.config['JWT_ALGORITHM']