mirror of https://github.com/status-im/codimd.git
Merge pull request #1453 from moycat/feature/oauth-avatar
Support avatar for OAuth users
This commit is contained in:
commit
1b80245546
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,6 +99,7 @@ module.exports = {
|
|||
userProfileUsernameAttr: 'username',
|
||||
userProfileDisplayNameAttr: 'displayName',
|
||||
userProfileEmailAttr: 'email',
|
||||
userProfilePhotoAttr: 'photo',
|
||||
scope: 'email'
|
||||
},
|
||||
facebook: {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue