From 55b79c4a71af046997a732c72c6293205a4f3f81 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 30 May 2022 11:44:58 +0200 Subject: [PATCH] backend: drop catalog user requirement from github sign-in Signed-off-by: Patrik Oldsberg --- packages/backend/src/plugins/auth.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/plugins/auth.ts b/packages/backend/src/plugins/auth.ts index cd0c42afe5..8beda6f3fb 100644 --- a/packages/backend/src/plugins/auth.ts +++ b/packages/backend/src/plugins/auth.ts @@ -44,7 +44,27 @@ export default async function createPlugin( // It is here for demo purposes only. github: providers.github.create({ signIn: { - resolver: providers.github.resolvers.usernameMatchingUserEntityName(), + async resolver({ result: { fullProfile } }, ctx) { + const userId = fullProfile.username; + if (!userId) { + throw new Error( + `GitHub user profile does not contain a username`, + ); + } + + const userEntityRef = stringifyEntityRef({ + kind: 'User', + name: userId, + namespace: DEFAULT_NAMESPACE, + }); + + return ctx.issueToken({ + claims: { + sub: userEntityRef, + ent: [userEntityRef], + }, + }); + }, }, }), gitlab: providers.gitlab.create({