Merge pull request #1453 from moycat/feature/oauth-avatar

Support avatar for OAuth users
This commit is contained in:
Raccoon 2020-03-26 05:17:27 +08:00 committed by GitHub
commit 1b80245546
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
}