Support avatar for OAuth users

Signed-off-by: Moycat <i@moy.cat>
This commit is contained in:
moycat 2020-03-12 13:39:27 +08:00 committed by Moycat
parent af5ad36167
commit 46fdb6a6f0
No known key found for this signature in database
GPG Key ID: CD3BDDB2B355E875
4 changed files with 10 additions and 2 deletions

View File

@ -7,6 +7,7 @@ function parseProfile (data) {
const username = extractProfileAttribute(data, config.oauth2.userProfileUsernameAttr)
const displayName = extractProfileAttribute(data, config.oauth2.userProfileDisplayNameAttr)
const email = extractProfileAttribute(data, config.oauth2.userProfileEmailAttr)
const photo = extractProfileAttribute(data, config.oauth2.userProfilePhotoAttr)
if (!username) {
throw new Error('cannot fetch username: please set correct CMD_OAUTH2_USER_PROFILE_USERNAME_ATTR')
@ -16,7 +17,8 @@ function parseProfile (data) {
id: username,
username: username,
displayName: displayName,
email: email
email: email,
photo: photo
}
}

View File

@ -99,6 +99,7 @@ module.exports = {
userProfileUsernameAttr: 'username',
userProfileDisplayNameAttr: 'displayName',
userProfileEmailAttr: 'email',
userProfilePhotoAttr: 'photo',
scope: 'email'
},
facebook: {

View File

@ -96,7 +96,8 @@ module.exports = {
scope: process.env.CMD_OAUTH2_SCOPE,
userProfileUsernameAttr: process.env.CMD_OAUTH2_USER_PROFILE_USERNAME_ATTR,
userProfileDisplayNameAttr: process.env.CMD_OAUTH2_USER_PROFILE_DISPLAY_NAME_ATTR,
userProfileEmailAttr: process.env.CMD_OAUTH2_USER_PROFILE_EMAIL_ATTR
userProfileEmailAttr: process.env.CMD_OAUTH2_USER_PROFILE_EMAIL_ATTR,
userProfilePhotoAttr: process.env.CMD_OAUTH2_USER_PROFILE_PHOTO_ATTR
},
dropbox: {
clientID: process.env.CMD_DROPBOX_CLIENTID,

View File

@ -140,6 +140,10 @@ module.exports = function (sequelize, DataTypes) {
case 'saml':
photo = generateAvatarURL(profile.username, profile.emails[0], bigger)
break
case 'oauth2':
photo = profile.photo
if (!photo) photo = generateAvatarURL(profile.username, profile.email, bigger)
break
}
return photo
}