João Fernandes
2022-03-18 11:08:53 -03:00
committed by João Fernandes
parent 9929e2402c
commit a41eae0936
+12 -4
View File
@@ -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 };
},