Add resolveCatalogMemberClaims method

Signed-off-by: Tim Hansen <timbonicus@gmail.com>
This commit is contained in:
Tim Hansen
2021-08-01 20:38:17 -06:00
parent 0e9fef8e3f
commit 29f7cfffb7
4 changed files with 227 additions and 6 deletions
+41
View File
@@ -111,6 +111,47 @@ export default async function createPlugin({
...
```
## Resolving membership through the catalog
If you want to provide additional claims through Sign-In resolvers but still
have the software catalog handle group (and transitive group) membership, you
can do this using the `CatalogIdentityClient` provided as context to Sign-In
resolvers:
```ts
export default async function createPlugin({
...
}: PluginEnvironment): Promise<Router> {
return await createRouter({
...
providerFactories: {
google: createGoogleProvider({
signIn: {
resolver: async ({ profile: { email } }, ctx) => {
const [sub] = email?.split('@') ?? '';
// Fetch from an external system that returns entity claims like:
// 'user:default/breanna.davison'
const ent = await externalSystemClient.getUsernames(email);
// Resolve group membership from the Backstage catalog
const claims = await ctx.catalogIdentityClient.resolveCatalogMemberClaims(
sub,
ent,
ctx.logger,
);
const token = await ctx.tokenIssuer.issueToken(claims);
return { sub, token };
},
},
}),
...
```
The `resolveCatalogMemberClaims` method will retrieve the `sub` and `ent`
entities from the catalog, if possible, and check for
[memberOf](../features/software-catalog/well-known-relations.md#memberof-and-hasmember)
relations to add additional entity claims.
## AuthHandler
Similar to a custom sign-in resolver, you can also write a custom auth handler