From fcc4e3c428aa70cdf467a653a07eb84897534cdb Mon Sep 17 00:00:00 2001 From: Tom Opdebeeck Date: Fri, 13 Aug 2021 11:26:04 +0200 Subject: [PATCH] fix(auth-backend): revert username added on profie Signed-off-by: Tom Opdebeeck --- .../src/lib/passport/PassportStrategyHelper.ts | 7 +------ .../auth-backend/src/providers/github/provider.test.ts | 4 ---- plugins/auth-backend/src/providers/github/provider.ts | 4 ++-- plugins/auth-backend/src/providers/gitlab/provider.ts | 10 +++++----- plugins/auth-backend/src/providers/types.ts | 4 ---- 5 files changed, 8 insertions(+), 21 deletions(-) diff --git a/plugins/auth-backend/src/lib/passport/PassportStrategyHelper.ts b/plugins/auth-backend/src/lib/passport/PassportStrategyHelper.ts index e6ef47c2c0..313b4a79bd 100644 --- a/plugins/auth-backend/src/lib/passport/PassportStrategyHelper.ts +++ b/plugins/auth-backend/src/lib/passport/PassportStrategyHelper.ts @@ -30,7 +30,7 @@ export const makeProfileInfo = ( profile: passport.Profile, idToken?: string, ): ProfileInfo => { - let { displayName, username } = profile; + let { displayName } = profile; let email: string | undefined = undefined; if (profile.emails && profile.emails.length > 0) { @@ -56,10 +56,6 @@ export const makeProfileInfo = ( if (!displayName && decoded.name) { displayName = decoded.name; } - - if (!username && decoded.username) { - username = decoded.username; - } } catch (e) { throw new Error(`Failed to parse id token and get profile info, ${e}`); } @@ -69,7 +65,6 @@ export const makeProfileInfo = ( email, picture, displayName, - username, }; }; diff --git a/plugins/auth-backend/src/providers/github/provider.test.ts b/plugins/auth-backend/src/providers/github/provider.test.ts index 5faa508f88..4e53ce4026 100644 --- a/plugins/auth-backend/src/providers/github/provider.test.ts +++ b/plugins/auth-backend/src/providers/github/provider.test.ts @@ -72,7 +72,6 @@ describe('GithubAuthProvider', () => { }, profile: { email: 'jimmymarkum@gmail.com', - username: 'jimmymarkum', displayName: 'Jimmy Markum', picture: 'https://a1cf74336522e87f135f-2f21ace9a6cf0052456644b80fa06d4f.ssl.cf2.rackcdn.com/images/characters_opt/p-mystic-river-sean-penn.jpg', @@ -118,7 +117,6 @@ describe('GithubAuthProvider', () => { }, profile: { displayName: 'Jimmy Markum', - username: 'jimmymarkum', picture: 'https://a1cf74336522e87f135f-2f21ace9a6cf0052456644b80fa06d4f.ssl.cf2.rackcdn.com/images/characters_opt/p-mystic-river-sean-penn.jpg', }, @@ -162,7 +160,6 @@ describe('GithubAuthProvider', () => { }, profile: { displayName: 'jimmymarkum', - username: 'jimmymarkum', picture: 'https://a1cf74336522e87f135f-2f21ace9a6cf0052456644b80fa06d4f.ssl.cf2.rackcdn.com/images/characters_opt/p-mystic-river-sean-penn.jpg', }, @@ -208,7 +205,6 @@ describe('GithubAuthProvider', () => { profile: { displayName: 'Dave Boyle', email: 'daveboyle@gitlab.org', - username: 'daveboyle', }, }; diff --git a/plugins/auth-backend/src/providers/github/provider.ts b/plugins/auth-backend/src/providers/github/provider.ts index 62f2534601..a550cd1fdc 100644 --- a/plugins/auth-backend/src/providers/github/provider.ts +++ b/plugins/auth-backend/src/providers/github/provider.ts @@ -79,7 +79,7 @@ export class GithubAuthProvider implements OAuthHandlers { const profile = makeProfileInfo( { ...fullProfile, - id: fullProfile.username || fullProfile.id, + id: fullProfile.id, displayName: fullProfile.displayName || fullProfile.username || fullProfile.id, }, @@ -95,7 +95,7 @@ export class GithubAuthProvider implements OAuthHandlers { expiresInSeconds: params.expires_in, }, backstageIdentity: { - id: fullProfile.username || fullProfile.id, + id: fullProfile.id, }, }, }; diff --git a/plugins/auth-backend/src/providers/gitlab/provider.ts b/plugins/auth-backend/src/providers/gitlab/provider.ts index d229165562..63d1260983 100644 --- a/plugins/auth-backend/src/providers/gitlab/provider.ts +++ b/plugins/auth-backend/src/providers/gitlab/provider.ts @@ -65,7 +65,7 @@ export type GitlabAuthProviderOptions = OAuthProviderOptions & { }; export const extractGitLabUserId = (profile: ProfileInfo): string => { - return profile.username || (profile.email?.split('@')[0] as string); + return profile.email?.split('@')[0] as string; }; export const gitlabDefaultSignInResolver: SignInResolver = async ( @@ -74,8 +74,8 @@ export const gitlabDefaultSignInResolver: SignInResolver = async ( ) => { const { profile } = info; - if (!profile.username && !profile.email) { - throw new Error('Profile contained no username or email'); + if (!profile.email) { + throw new Error('Profile contained no email'); } const id = extractGitLabUserId(profile); @@ -238,8 +238,8 @@ export class GitlabAuthProvider implements OAuthHandlers { const profile = makeProfileInfo(fullProfile); - if (!profile.username && !profile.email) { - throw new Error('Profile contained no username or email'); + if (!profile.email) { + throw new Error('Profile contained no email'); } fullProfile.id = extractGitLabUserId(profile); diff --git a/plugins/auth-backend/src/providers/types.ts b/plugins/auth-backend/src/providers/types.ts index a8b087156d..c838005c00 100644 --- a/plugins/auth-backend/src/providers/types.ts +++ b/plugins/auth-backend/src/providers/types.ts @@ -196,10 +196,6 @@ export type ProfileInfo = { * signed in user. */ picture?: string; - /** - * Username of the signed in user. - */ - username?: string; }; export type SignInInfo = {