我正在尝试在我的后台实例中开发一个内部插件。我从一个简单的插件开始,从外部 API 检索数据,但我遇到了这个错误:
"error": {
"name": "AuthenticationError",
"message": "Illegal token",
"stack": "AuthenticationError: Illegal token\n at DefaultAuthService.authenticate (/home/user/project-v1/instance-backstage/node_modules/@backstage/backend-defaults/src/entrypoints/auth/DefaultAuthService.ts:101:11)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async DefaultHttpAuthService.#extractCredentialsFromRequest (/home/user/project-v1/instance-backstage/node_modules/@backstage/backend-defaults/src/entrypoints/httpAuth/httpAuthServiceFactory.ts:95:12)\n at async DefaultHttpAuthService.credentials (/home/user/project-v1/instance-backstage/node_modules/@backstage/backend-defaults/src/entrypoints/httpAuth/httpAuthServiceFactory.ts:138:9)"
},
"request": {
"method": "GET",
"url": "/api/newplugin-backend/applications"
},
"response": {
经过一番研究,我发现新的后台使用“默认安全”插件模型。
https://backstage.io/docs/plugins/backend-plugin/
所以我按照文档中的说明进行操作,并尝试通过添加以下内容来禁用身份验证:
httpRouter.addAuthPolicy({
path: '/api/newplugin-backend/applications',
allow: 'unauthenticated',
});
但我仍然遇到同样的错误。
我什至尝试通过以下方式使用用户的身份(我使用默认的来宾用户):
deps: {
httpAuth: coreServices.httpAuth,
userInfo: coreServices.userInfo,
},
async init({
httpAuth,
userInfo,
}) {
httpRouter.use(
await createRouter({
httpAuth,
userInfo,
logger,
}),
);
}
但是,我仍然遇到同样的错误 - 请提供如何解决它的任何帮助或建议吗?
假设“pluginId”属性设置为“newplugin-backend”,我认为您应该从“path”值中删除“/api/newplugin-backend”,如下所示:
httpRouter.addAuthPolicy({ 路径:'/应用程序', 允许:“未经身份验证”, });