Skip to content

Commit 1b80245

Browse files
authored
Merge pull request #1453 from moycat/feature/oauth-avatar
Support avatar for OAuth users
2 parents a8da632 + 46fdb6a commit 1b80245

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

lib/auth/oauth2/strategy.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function parseProfile (data) {
77
const username = extractProfileAttribute(data, config.oauth2.userProfileUsernameAttr)
88
const displayName = extractProfileAttribute(data, config.oauth2.userProfileDisplayNameAttr)
99
const email = extractProfileAttribute(data, config.oauth2.userProfileEmailAttr)
10+
const photo = extractProfileAttribute(data, config.oauth2.userProfilePhotoAttr)
1011

1112
if (!username) {
1213
throw new Error('cannot fetch username: please set correct CMD_OAUTH2_USER_PROFILE_USERNAME_ATTR')
@@ -16,7 +17,8 @@ function parseProfile (data) {
1617
id: username,
1718
username: username,
1819
displayName: displayName,
19-
email: email
20+
email: email,
21+
photo: photo
2022
}
2123
}
2224

lib/config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ module.exports = {
9999
userProfileUsernameAttr: 'username',
100100
userProfileDisplayNameAttr: 'displayName',
101101
userProfileEmailAttr: 'email',
102+
userProfilePhotoAttr: 'photo',
102103
scope: 'email'
103104
},
104105
facebook: {

lib/config/environment.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ module.exports = {
9696
scope: process.env.CMD_OAUTH2_SCOPE,
9797
userProfileUsernameAttr: process.env.CMD_OAUTH2_USER_PROFILE_USERNAME_ATTR,
9898
userProfileDisplayNameAttr: process.env.CMD_OAUTH2_USER_PROFILE_DISPLAY_NAME_ATTR,
99-
userProfileEmailAttr: process.env.CMD_OAUTH2_USER_PROFILE_EMAIL_ATTR
99+
userProfileEmailAttr: process.env.CMD_OAUTH2_USER_PROFILE_EMAIL_ATTR,
100+
userProfilePhotoAttr: process.env.CMD_OAUTH2_USER_PROFILE_PHOTO_ATTR
100101
},
101102
dropbox: {
102103
clientID: process.env.CMD_DROPBOX_CLIENTID,

lib/models/user.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ module.exports = function (sequelize, DataTypes) {
140140
case 'saml':
141141
photo = generateAvatarURL(profile.username, profile.emails[0], bigger)
142142
break
143+
case 'oauth2':
144+
photo = profile.photo
145+
if (!photo) photo = generateAvatarURL(profile.username, profile.email, bigger)
146+
break
143147
}
144148
return photo
145149
}

0 commit comments

Comments
 (0)