希望你一切都好!我正在寻求某种帮助。如果您向我提供某种提示,我将非常感激。
我正在根据入门文档说明设置基于 [Backstage.io][1] 的开发者门户。
我已将 @backstage/plugin-auth-backend 添加到项目根目录并按照[此处][2]所述进行配置。
当我尝试加载后台网络应用程序时,我收到以下错误:
{"error":{"name":"AuthenticationError","message":"Refresh failed; caused by InputError: Missing session cookie"
后面是有错误的 .ts 文件列表,包括一些与 node_modules/@backstage/plugin-auth-backend 连接的脚本。伙计们,我真的不知道我在哪里遗漏了一些东西。
以下是我的 app-config.yaml 中的一些关键点:
app:
title: Scaffolded Backstage App
baseUrl: http://0.0.0.0:3000
backend:
baseUrl: http://<publicIP>:7007
listen:
port: 7007
csp:
default-src: ["'self'", 'http:', 'https:']
connect-src: ["'self'", 'http:', 'https:']
script-src: ["'self", 'http:', 'https:','unsafe-inline', http://www.github.com", http://api.github.com"]
cors:
origin: http://*:3000
methods: [GET, POST, PUT, DELETE]
credentials: true
headers: X-Requested-With
auth:
environment: development
providers:
github:
development:
clientId: ${GITHUB_CLIENTID}
clientSecret: ${GITHUB_CLIENT_SECRET}
我已将这些环境变量导出到当前终端并运行
yarn dev
因此,当我尝试使用 Github 登录 Backstage 时,在尝试访问请求 URL 时收到
401 Unathorized
错误响应:http://<publicIP>:7007/api/auth/github/refresh?optional&env=development
[1]:https://backstage.io/
[2]:https://backstage.io/docs/auth/add-auth-provider
他们目前正在更改配置身份验证的方式。
有关此主题的讨论正在进行中:https://github.com/backstage/backstage/issues/23748
我能够在 localhost 后台实例的后台配置 GitHub 的身份验证。
先决条件:
http://localhost:7007/api/auth/github
添加配置:
app-config.yaml
(注意resolvers
部分)auth:
# see https://backstage.io/docs/auth/ to learn about auth providers
environment: production
providers:
guest: {}
github:
production:
clientId: <valueOrVar>
clientSecret: <valueOrVar>
signIn:
resolvers:
- resolver: emailMatchingUserEntityProfileEmail
- resolver: emailLocalPartMatchingUserEntityName
- resolver: usernameMatchingUserEntityName
packages/backend/src/index.ts
backend.add(import('@backstage/plugin-auth-backend-module-github-provider'));
packages/app/src/App.tsx
(此处文档错误:无需导入 SignInPage;仔细阅读下一个片段的注释)// add import
import { githubAuthApiRef } from '@backstage/core-plugin-api';
// add the following in createApp function after 'apis,' line
components: {
SignInPage: props => (
<SignInPage
{...props}
auto
provider={{
id: 'github-auth-provider',
title: 'GitHub',
message: 'Sign in using GitHub',
apiRef: githubAuthApiRef,
}}
/>
),
},
examples/org.yaml
:将 guest 更改为 GitHub 用户名