我很难让Auth0集成正常工作。我收到如下所示的回复
{
"name": "NotAuthenticated",
"message": "error:0909006C:PEM routines:get_name:no start line",
"code": 401,
"className": "not-authenticated",
"data": {
"library": "PEM routines",
"function": "get_name",
"reason": "no start line",
"code": "ERR_OSSL_PEM_NO_START_LINE"
},
"errors": {}
}
使用标题进行GET
至https://localhost:433/users
时>
{ Authorization: Bearer REMOVED }
上面的
REMOVED
部分是调用返回的令牌
curl 'http://localhost:3030/users/' -H 'Content-Type: application/json'
这里是我的
default.json
{ "host": "localhost", "port": 433, "public": "../public/", "paginate": { "default": 10, "max": 50 }, "authentication": { "entity": "user", "service": "users", "secret": "REMOVED", "authStrategies": [ "jwt", "local" ], "jwtOptions": { "header": { "typ": "access" }, "audience": "http://vice-node-boilerplate", "issuer": "feathers", "algorithm": "RS256", "expiresIn": "1d" }, "local": { "usernameField": "email", "passwordField": "password" }, "oauth": { "redirect": "/", "auth0": { "key": "REMOVED", "secret": "REMOVED", "subdomain": "vicesoftware" } } }, "postgres": "postgres://postgres:@localhost:5432/vice_node_boilerplate" }
我更新了
authentication.js
,如下所示
const { AuthenticationService, JWTStrategy } = require('@feathersjs/authentication'); const { LocalStrategy } = require('@feathersjs/authentication-local'); const { expressOauth, OAuthStrategy } = require('@feathersjs/authentication-oauth'); class Auth0Strategy extends OAuthStrategy { async getEntityData(profile) { const baseData = await super.getEntityData(profile); return { ...baseData, email: profile.email }; } } module.exports = app => { const authentication = new AuthenticationService(app); authentication.register('jwt', new JWTStrategy()); authentication.register('local', new LocalStrategy()); authentication.register('auth0', new Auth0Strategy()); app.use('/authentication', authentication); app.configure(expressOauth()); };
并且我已经更新了
index.js
,如下所示
/* eslint-disable no-console */ const https = require('https'); const fs = require('fs'); const logger = require('./logger'); const app = require('./app'); const port = app.get('port'); const key = fs.readFileSync(__dirname + '/localhost-key.pem'); const cert = fs.readFileSync(__dirname + '/localhost.pem'); if (!key) { throw Error("Unable to read certificate key file"); } if (!cert){ throw Error("Unable to read certificate cert key file"); } const server = https.createServer({ key, cert }, app).listen(port); process.on('unhandledRejection', (reason, p) => logger.error('Unhandled Rejection at: Promise ', p, reason) ); server.on('listening', () => logger.info('Feathers application started on http://%s:%d', app.get('host'), port) );
我按照此处的说明生成了本地开发证书文件
localhost-key.pem
和localhost.pem
:https://auth0.com/docs/libraries/secure-local-development
编辑1
请注意,我还尝试使用来自node.js文档的以下指令生成证书:https://nodejs.org/en/knowledge/HTTP/servers/how-to-create-a-HTTPS-server/我很难让Auth0集成正常工作。我收到如下所示的响应{“名称”:“ NotAuthenticated”,“消息”:“错误:0909006C:PEM例程:get_name:无起始行”,...
您将jwtOptions.algorithm
配置更改为RS256
。这需要其他配置,特别是有效的私钥。该错误表明提供的私钥无效。更多信息可以在node-jsonwebtoken documentation中找到。如果您不确定,我建议使用默认的HS256/384/512
算法。