[英]How to integrate auth step into feathers service
我正在尝试将 jwt/local auth 集成到对羽毛的任何调用中。 因此,通过在它授权的任何调用中包含 user/pass,而不是要求之前单独调用 /authorization 端点并将 header 传递给后续调用。 我尝试使用身份验证,但它没有从挂钩中看到我的身份验证策略。 这是当前的创建代码,它确实返回 jwt 令牌,但是我如何从这里进行身份验证并将数据库中的用户数据集成到上下文中,就像身份验证通常那样?
module.exports = (options = {}) => {
return async (context) => {
let promise = new Promise((resolve, reject) => {
context.app
.service("authentication")
.create({
username: context.data.username,
password: context.data.password,
strategy:"local"
})
.then((response) => {
console.log(response)
context.arguments[1]['Authorization'] = response.accessToken
resolve(context);
});
});
let result = await promise;
if (result) {
return context;
}
};
};
authenticate 挂钩可以采用任何策略,并将查找您在params.authentication
中传递的任何内容。 在您的示例中,以下内容:
module.exports = (options = {}) => {
return async (context) => {
context.params = {
...context.params,
authentication: {
strategy: 'local',
username: context.data.username,
password: context.data.password
}
}
return context;
};
};
将允许authenticate('local')
运行。 如果你想从 HTTP 请求中获取身份验证信息,你可以在自定义策略中实现parse(req, res)方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.