From 81fa98b3abefa3fef87706c6c1fd944e2503f0ad Mon Sep 17 00:00:00 2001 From: Teun Willems Date: Thu, 1 Apr 2021 14:07:24 +0200 Subject: [PATCH 1/2] fix: displays name from jwt instead of using email address Signed-off-by: Teun Willems --- .../src/lib/passport/PassportStrategyHelper.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/auth-backend/src/lib/passport/PassportStrategyHelper.ts b/plugins/auth-backend/src/lib/passport/PassportStrategyHelper.ts index 8819da0a2f..a82e428a83 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 => { - const { displayName } = profile; + let { displayName } = profile; let email: string | undefined = undefined; if (profile.emails && profile.emails.length > 0) { @@ -44,7 +44,7 @@ export const makeProfileInfo = ( picture = firstPhoto.value; } - if ((!email || !picture) && idToken) { + if ((!email || !picture || !displayName) && idToken) { try { const decoded: Record = jwtDecoder(idToken); if (!email && decoded.email) { @@ -53,6 +53,9 @@ export const makeProfileInfo = ( if (!picture && decoded.picture) { picture = decoded.picture; } + if (!displayName && decoded.name) { + displayName = decoded.name; + } } catch (e) { throw new Error(`Failed to parse id token and get profile info, ${e}`); } From 2b2b3118640e44a325e601c0706d407d237e31a0 Mon Sep 17 00:00:00 2001 From: Teun Willems Date: Thu, 1 Apr 2021 14:13:01 +0200 Subject: [PATCH 2/2] chore: adds changeset Signed-off-by: Teun Willems --- .changeset/forty-ladybugs-move.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/forty-ladybugs-move.md diff --git a/.changeset/forty-ladybugs-move.md b/.changeset/forty-ladybugs-move.md new file mode 100644 index 0000000000..254efea584 --- /dev/null +++ b/.changeset/forty-ladybugs-move.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-auth-backend': patch +--- + +When using OAuth2 authentication the name is now taken from the name property of the JWT instead of the email property