简体   繁体   English

如何在 Backstage 上启用 Google 登录?

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

On Backstage, after following all the steps on https://backstage.io/docs/auth/google/provider , I get the message "The Google provider is not configured to support sign-in" after going through the Google SSO interface.在 Backstage 上,按照https://backstage.io/docs/auth/google/provider上的所有步骤操作后,通过 Google SSO 界面后,我收到消息“Google 提供程序未配置为支持登录”。

If I understood correctly, I have to setup Backstage to enable/allow Google provider to sign-in users.如果我理解正确,我必须设置 Backstage 以启用/允许 Google 提供商登录用户。 But I'm lost on how to do this.但我不知道如何做到这一点。

How to configure Google provider to support sign-in on Backstage?如何配置 Google 提供商以支持在 Backstage 上登录?

在此处输入图像描述

It seems you missed the backend app's auth plugin configuration as mentioned in the docs您似乎错过了文档中提到的后端应用程序的身份验证插件配置

You should create a resolver function to map the google's user identity to a backstage's user identity or, optionally, skip the catalog's user lookup ( there are caveats to this approach ).您应该创建一个解析器函数来将 google 的用户身份映射到后台的用户身份,或者可以选择跳过目录的用户查找(这种方法有一些注意事项)。

The following documentation explains about the resolver function and user identities: Sign-in Identities and Resolvers以下文档解释了解析器功能和用户身份:登录身份和解析器

The following code is an example of how you would achieve a google resolver WITHOUT mapping to a backstage user identity and I recommend using it for testing purposes only and, as previosly mentioned, there are caveats to this approach.以下代码是一个示例,说明如何在不映射到后台用户身份的情况下实现 google 解析器,我建议仅将其用于测试目的,如前所述,这种方法有一些注意事项 I strongly recommend understanding the documentation and the power mapping the external user identity to a backstage user identity unleashes.我强烈建议您了解将外部用户身份映射到后台用户身份的文档和权力释放。

./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