fix(auth-backend): revert username added on profie

Signed-off-by: Tom Opdebeeck <tom.opdebeeck@studiohyperdrive.be>
This commit is contained in:
Tom Opdebeeck
2021-08-13 11:26:04 +02:00
parent 39fc3d7f80
commit fcc4e3c428
5 changed files with 8 additions and 21 deletions
@@ -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,
};
};
@@ -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',
},
};
@@ -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,
},
},
};
@@ -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<OAuthResult> = async (
@@ -74,8 +74,8 @@ export const gitlabDefaultSignInResolver: SignInResolver<OAuthResult> = 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);
@@ -196,10 +196,6 @@ export type ProfileInfo = {
* signed in user.
*/
picture?: string;
/**
* Username of the signed in user.
*/
username?: string;
};
export type SignInInfo<AuthResult> = {