Merge pull request #5199 from teunw/fix/display-name-from-jwt
fix: displays name from jwt instead of using email address
This commit is contained in:
@@ -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
|
||||
@@ -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<string, string> = 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}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user