update google auth provider example to use entity ref for the token subject
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 <joaofnds@joaofnds.com>
This commit is contained in:
committed by
João Fernandes
parent
9929e2402c
commit
a41eae0936
@@ -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<Router> {
|
||||
@@ -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 };
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user