From 6e983ba5dcb605a1f7bb7e8d0a1eb0ad82b3d922 Mon Sep 17 00:00:00 2001 From: Erik Michelson Date: Fri, 7 Jan 2022 14:01:32 +0100 Subject: [PATCH] Use libravatar image if email address is defined We use the attribute `emails` (plural) for email addresses with other auth providers like LDAP or SAML. In case of OAuth2 we used the attribute `email` (singular) which resulted in problems. Furthermore the OAuth2 strategy fell into the default fallback of the provider switch statement. This statement did not check email addresses but did generate the letter-avatar instantly. Signed-off-by: Erik Michelson --- lib/models/user.js | 4 ++++ lib/web/auth/oauth2/index.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/models/user.js b/lib/models/user.js index d79530039..5532e5b31 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -133,6 +133,10 @@ module.exports = function (sequelize, DataTypes) { photo = generateAvatarURL(profile.username, profile.emails[0], bigger) break default: + if (profile.emails && profile.emails.length > 0) { + photo = generateAvatarURL(profile.username, profile.emails[0]) + break + } photo = generateAvatarURL(profile.username) break } diff --git a/lib/web/auth/oauth2/index.js b/lib/web/auth/oauth2/index.js index e9032e0b1..feef5e7f9 100644 --- a/lib/web/auth/oauth2/index.js +++ b/lib/web/auth/oauth2/index.js @@ -62,7 +62,7 @@ function parseProfile (data) { id: id || username, username: username, displayName: displayName, - email: email + emails: email ? [email] : [] } }