Javascript 无电子邮件的身份验证
我在寻找一个身份验证系统,其中用户提交到一个enpoint,并在该端点生成一个jwt,我不确定如何实现这一点,我的客户端应用程序不使用电子邮件地址或存储的信息,它实际上是一个dApp。我只需要一个端点,它将根据提供的种子短语和密码计算一个值。如果这些值的处理进展顺利(除非有人向端点发送垃圾邮件,否则几乎总是如此),那么将发出jwt。。到目前为止,feathers cli的开箱即用功能意味着我需要使用本地策略和电子邮件地址,我找不到任何关于此的演示。。有人有什么建议吗?到目前为止,我的授权是相当默认的Javascript 无电子邮件的身份验证,javascript,express,feathersjs,feathers-authentication,Javascript,Express,Feathersjs,Feathers Authentication,我在寻找一个身份验证系统,其中用户提交到一个enpoint,并在该端点生成一个jwt,我不确定如何实现这一点,我的客户端应用程序不使用电子邮件地址或存储的信息,它实际上是一个dApp。我只需要一个端点,它将根据提供的种子短语和密码计算一个值。如果这些值的处理进展顺利(除非有人向端点发送垃圾邮件,否则几乎总是如此),那么将发出jwt。。到目前为止,feathers cli的开箱即用功能意味着我需要使用本地策略和电子邮件地址,我找不到任何关于此的演示。。有人有什么建议吗?到目前为止,我的授权是相当默
const authentication = require('@feathersjs/authentication');
const jwt = require('@feathersjs/authentication-jwt');
const local = require('@feathersjs/authentication-local');
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());
// The `authentication` service is used to create a JWT.
// The before `create` hook registers strategies that can be used
// to create a new valid JWT (e.g. local or oauth2)
app.service('authentication').hooks({
before: {
create: [
authentication.hooks.authenticate(config.strategies)
],
remove: [
authentication.hooks.authenticate('jwt')
]
}
});
};
以下是我的服务:
// Initializes the `aerAuth` service on path `/userauthendpoint`
const createService = require('feathers-memory');
const hooks = require('./userauthendpoint.hooks');
module.exports = function (app) {
const paginate = app.get('paginate');
const options = {
name: 'userauthendpoint',
paginate
};
// Initialize our service with any options it requires
app.use('/userauthendpoint', createService(options) );
// Get our initialized service so that we can register hooks and filters
const service = app.service('userauthendpoint');
service.hooks(hooks);
};
我对Feather比较陌生,但对构建auth系统(PHP)不太熟悉。指南和插件可能允许您完成所需的工作
这还取决于您希望如何实现这一点。您可以对每个服务使用自定义策略(如每个请求都必须在头中发送的API密钥),也可以在/authentication
服务之前使用自定义策略,以允许创建JWT(这里的问题是它需要引用数据库中不存在的userId
或其他entityId
)
最简单的方法是使用第一个选项和自定义标题(X-DAP-PASSWORD
),该标题可能如下所示:
const custom = require('feathers-authentication-custom');
app.configure(authentication(settings));
app.configure(custom((req, done) => {
const password = req.headers['x-dap-password'];
if(checkPassword(req.app.get('seedPassphrase'), password)) {
// implement your own custom logic for loading and verifying the user
done(null, user);
} else {
done(new Error('Invalid passphrase'));
}
}));