feathersjs - Feathers auth 登录无效
问题描述
我尝试使用本地身份验证,但收到错误消息“无效登录”。
- 我从客户端发送“本地”身份验证。服务器收到数据
{ strategy: 'local',
email: 'email@gmail.com',
password: '123' },
{ query: {},
provider: 'socketio',
headers: {},
session: {},
cookies: {} }
在 authentication.js 中
module.exports = function (app) {
const config = app.get('authentication');
// Set up authentication with the secret
app.configure(authentication(config));
app.configure(jwt());
app.configure(local());
app.configure(oauth2(Object.assign({
name: 'auth0',
Strategy: Auth0Strategy
}, config.auth0)));
app.service('authentication').hooks({
before: {
create: [
(data)=>{console.log('auth',data.arguments)},
authentication.hooks.authenticate(config.strategies),
],
remove: [
authentication.hooks.authenticate('jwt')
]
}
});
};
- 服务器在数据库中查找记录并返回查询结果
{ id: 1,
email: 'email@gmail.com',
password:
'$2a$13$t2XZsqu/0t5jKSdbRUyZTOVOoZJVtiha3sN/Z8N0O190Z0DUJj70O',
auth0Id: null,
isVerified: null,
verifyToken: 'string',
verifyExpires: null,
resetToken: 'string',
resetExpires: null,
createdAt: 2019-04-14T22:04:52.000Z,
updatedAt: 2019-04-14T22:04:52.000Z }
- 之后,它尝试比较密码的哈希值,但接收到的密码的哈希值不等于查询结果中的密码。收到的密码与结果哈希中的当前时间相结合。
如何在羽毛中使用本地身份验证?
UPD
来自 default.json 的配置
"authentication": {
"secret": "my secret key here",
"strategies": [
"jwt",
"local"
],
"path": "/authentication",
"service": "users",
"jwt": {
"header": {
"typ": "access"
},
"audience": "https://yourdomain.com",
"subject": "anonymous",
"issuer": "feathers",
"algorithm": "HS256",
"expiresIn": "1d"
},
"local": {
"entity": "user",
"usernameField": "email",
"passwordField": "password"
},
"auth0": {
"clientID": "your auth0 client id",
"clientSecret": "your auth0 client secret",
"successRedirect": "/",
"domain": "mydomain.auth0.com",
"scopes": [
"profile"
]
}
}
解决方案
实际上,bcrypt(由羽毛在内部用于散列)正在使用盐来散列我们的密码,这就是为什么每次使用相同的字符串都会得到不同的不同结果的原因。
推荐阅读
- function - 替换已弃用的 create_function 方法
- c++ - C++ - 在自定义数据类型向量中按值匹配和替换元素
- java - 如何使用java记录在selenium中启动的chrome浏览器会话
- spring - 在单元测试期间注入 Drools StatefulKnowledgeSession 的实例
- typescript - 向用户询问 VSCode 扩展中的几个值
- elasticsearch - 在 Kibana date_histogram 聚合中使用数字字段作为日期
- docker - 如何将 docker 容器变成僵尸
- c++ - C ++如何拥有相同方法的不同版本?
- eclipse - 如何将eclipse默认对话框更改为调试配置对话框
- c# - C# 表达式自行转换为不同的表达式