From fe8aa1547387a64a2e13568a4bd8124df7759ee3 Mon Sep 17 00:00:00 2001 From: Tim Urista Date: Mon, 6 Jul 2020 09:47:19 -0700 Subject: [PATCH] add email for backstage profile --- .../core/src/layout/SignInPage/gitlabProvider.tsx | 2 +- plugins/auth-backend/src/providers/gitlab/provider.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/core/src/layout/SignInPage/gitlabProvider.tsx b/packages/core/src/layout/SignInPage/gitlabProvider.tsx index 790e03c230..5e417cb32d 100644 --- a/packages/core/src/layout/SignInPage/gitlabProvider.tsx +++ b/packages/core/src/layout/SignInPage/gitlabProvider.tsx @@ -32,7 +32,7 @@ const Component: ProviderComponent = ({ onResult }) => { const profile = await gitlabAuthApi.getProfile(); onResult({ - userId: identity?.id || profile.email, + userId: identity!.id, profile: profile!, getIdToken: () => gitlabAuthApi.getBackstageIdentity().then(i => i!.idToken), diff --git a/plugins/auth-backend/src/providers/gitlab/provider.ts b/plugins/auth-backend/src/providers/gitlab/provider.ts index 890fbb3531..950c414750 100644 --- a/plugins/auth-backend/src/providers/gitlab/provider.ts +++ b/plugins/auth-backend/src/providers/gitlab/provider.ts @@ -78,6 +78,14 @@ export class GitlabAuthProvider implements OAuthProviderHandlers { idToken: params.id_token, }; + // gitlab provides an id numeric value (123) + // as a fallback + let id = passportProfile!.id; + + if (profile.email) { + id = profile.email.split('@')[0]; + } + if (params.expires_in) { providerInfo.expiresInSeconds = params.expires_in; } @@ -87,6 +95,9 @@ export class GitlabAuthProvider implements OAuthProviderHandlers { return { providerInfo, profile, + backstageIdentity: { + id, + }, }; }