From a41eae09366079900c27b28db2e73d1785b734d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Fernandes?= Date: Fri, 18 Mar 2022 11:08:53 -0300 Subject: [PATCH] update google auth provider example to use entity ref for the token subject MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit plugin-auth-backend broke started requiring a full entity ref on version [0.12.0](https://github.com/backstage/backstage/blob/master/plugins/auth-backend/CHANGELOG.md#0120) see: https://github.com/backstage/backstage/releases/tag/v0.70.0 https://github.com/backstage/backstage/blob/master/plugins/auth-backend/CHANGELOG.md#0120 https://github.com/backstage/backstage/commit/0c8ba31d72670d9ff5eda3ca726e061fff088115 Signed-off-by: João Fernandes --- docs/auth/identity-resolver.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/auth/identity-resolver.md b/docs/auth/identity-resolver.md index c336da38dd..fea82894c8 100644 --- a/docs/auth/identity-resolver.md +++ b/docs/auth/identity-resolver.md @@ -51,11 +51,12 @@ export default async function createPlugin( // Let's use the username in the email ID as the user's default // unique identifier inside Backstage. const [id] = email.split('@'); - ent.push(stringifyEntityRef({ + const userEntityRef = stringifyEntityRef({ kind: 'User', namespace: DEFAULT_NAMESPACE, name: id, - })); + }); + ent.push(userEntityRef); // Let's call the internal LDAP provider to get a list of groups // that the user belongs to, and add those to the list as well @@ -68,7 +69,7 @@ export default async function createPlugin( // Issue the token containing the entity claims const token = await ctx.tokenIssuer.issueToken({ - claims: { sub: id, ent }, + claims: { sub: userEntityRef, ent }, }); return { id, token }; }, @@ -130,6 +131,8 @@ can do this using the `CatalogIdentityClient` provided as context to Sign-In resolvers: ```ts +import { DEFAULT_NAMESPACE, stringifyEntityRef } from '@backstage/catalog-model'; + export default async function createPlugin( env: PluginEnvironment, ): Promise { @@ -140,6 +143,11 @@ export default async function createPlugin( signIn: { resolver: async ({ profile: { email } }, ctx) => { const [id] = email?.split('@') ?? ''; + const userEntityRef = stringifyEntityRef({ + kind: 'User', + namespace: DEFAULT_NAMESPACE, + name: id, + }); // Fetch from an external system that returns entity claims like: // ['user:default/breanna.davison', ...] const ent = await externalSystemClient.getUsernames(email); @@ -150,7 +158,7 @@ export default async function createPlugin( logger: ctx.logger, }); const token = await ctx.tokenIssuer.issueToken({ - claims: { sub: id, ent: fullEnt }, + claims: { sub: userEntityRef, ent: fullEnt }, }); return { id, token }; },