繁体   English   中英

如何在 Backstage 上启用 Google 登录?

[英]How to enable sign-in with Google on Backstage?

在 Backstage 上,按照https://backstage.io/docs/auth/google/provider上的所有步骤操作后,通过 Google SSO 界面后,我收到消息“Google 提供程序未配置为支持登录”。

如果我理解正确,我必须设置 Backstage 以启用/允许 Google 提供商登录用户。 但我不知道如何做到这一点。

如何配置 Google 提供商以支持在 Backstage 上登录?

在此处输入图像描述

您似乎错过了文档中提到的后端应用程序的身份验证插件配置

您应该创建一个解析器函数来将 google 的用户身份映射到后台的用户身份,或者可以选择跳过目录的用户查找(这种方法有一些注意事项)。

以下文档解释了解析器功能和用户身份:登录身份和解析器

以下代码是一个示例,说明如何在不映射到后台用户身份的情况下实现 google 解析器,我建议仅将其用于测试目的,如前所述,这种方法有一些注意事项 我强烈建议您了解将外部用户身份映射到后台用户身份的文档和权力释放。

./packages/backend/src/plugins/auth.ts

 import { createRouter, providers } from '@backstage/plugin-auth-backend'; import { Router } from 'express'; import { PluginEnvironment } from '../types'; import { DEFAULT_NAMESPACE, stringifyEntityRef, } from '@backstage/catalog-model'; export default async function createPlugin( env: PluginEnvironment, ): Promise<Router> { return await createRouter({ ...env, providerFactories: { google: providers.google.create({ signIn: { resolver: async ({ profile }, ctx) => { if (!profile.email) { throw new Error( 'Login failed, user profile does not contain an email', ); } const [localPart] = profile.email.split('@'); const userEntityRef = stringifyEntityRef({ kind: 'User', name: localPart, namespace: DEFAULT_NAMESPACE, }); return ctx.issueToken({ claims: { sub: userEntityRef, ent: [userEntityRef], }, }); }, }, }), }, }); }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM