feat(gcp-iap): Add user id annotation resolver

Signed-off-by: Nikolai Røed Kristiansen <nikolai.kristiansen@remarkable.no>
This commit is contained in:
Nikolai Røed Kristiansen
2024-04-11 13:01:13 +02:00
parent dd44406163
commit e0ed31c0c4
3 changed files with 26 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-auth-backend-module-gcp-iap-provider': minor
---
Add user id annotation sign-in resolver
@@ -37,6 +37,10 @@ export namespace gcpIapSignInResolvers {
GcpIapResult,
unknown
>;
const idMatchingUserEntityAnnotation: SignInResolverFactory<
GcpIapResult,
unknown
>;
}
// @public
@@ -46,4 +46,21 @@ export namespace gcpIapSignInResolvers {
};
},
});
/**
* Looks up the user by matching their user ID to the `google.com/user-id` annotation.
*/
export const idMatchingUserEntityAnnotation = createSignInResolverFactory({
create() {
return async (info: SignInInfo<GcpIapResult>, ctx) => {
const userId = info.result.iapToken.sub.split(':')[1];
return ctx.signInWithCatalogUser({
annotations: {
'google.com/user-id': userId,
},
});
};
},
});
}