Skip to content

Commit 6ae53bf

Browse files
authored
feat: map OIDC/OAuth2 avatar claims to user pictureUrl (#7908)
1 parent 3dcf20a commit 6ae53bf

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

server/modules/authentication/oauth2/authentication.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ module.exports = {
2222
state: conf.enableCSRFProtection
2323
}, async (req, accessToken, refreshToken, profile, cb) => {
2424
try {
25+
const picture = _.get(profile, conf.pictureClaim, '')
2526
const user = await WIKI.models.users.processProfile({
2627
providerKey: req.params.strategy,
2728
profile: {
2829
...profile,
2930
id: _.get(profile, conf.userIdClaim),
3031
displayName: _.get(profile, conf.displayNameClaim, '???'),
31-
email: _.get(profile, conf.emailClaim)
32+
email: _.get(profile, conf.emailClaim),
33+
picture: picture
3234
}
3335
})
3436
if (conf.mapGroups) {

server/modules/authentication/oauth2/definition.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,38 +54,45 @@ props:
5454
default: email
5555
maxWidth: 500
5656
order: 8
57+
pictureClaim:
58+
type: String
59+
title: Picture Claim
60+
hint: Field containing the user avatar URL
61+
default: picture
62+
maxWidth: 500
63+
order: 9
5764
mapGroups:
5865
type: Boolean
5966
title: Map Groups
6067
hint: Map groups matching names from the groups claim value
6168
default: false
62-
order: 9
69+
order: 10
6370
groupsClaim:
6471
type: String
6572
title: Groups Claim
6673
hint: Field containing the group names
6774
default: groups
6875
maxWidth: 500
69-
order: 10
76+
order: 11
7077
logoutURL:
7178
type: String
7279
title: Logout URL
7380
hint: (optional) Logout URL on the OAuth2 provider where the user will be redirected to complete the logout process.
74-
order: 11
81+
order: 12
7582
scope:
7683
type: String
7784
title: Scope
7885
hint: (optional) Application Client permission scopes.
79-
order: 12
86+
order: 13
8087
useQueryStringForAccessToken:
8188
type: Boolean
8289
default: false
8390
title: Pass access token via GET query string to User Info Endpoint
8491
hint: (optional) Pass the access token in an `access_token` parameter attached to the GET query string of the User Info Endpoint URL. Otherwise the access token will be passed in the Authorization header.
85-
order: 13
92+
order: 14
8693
enableCSRFProtection:
8794
type: Boolean
8895
default: true
8996
title: Enable CSRF protection
9097
hint: Pass a nonce state parameter during authentication to protect against CSRF attacks.
91-
order: 14
98+
order: 15

server/modules/authentication/oidc/authentication.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ module.exports = {
2424
acrValues: conf.acrValues
2525
}, async (req, iss, uiProfile, idProfile, context, idToken, accessToken, refreshToken, params, cb) => {
2626
const profile = Object.assign({}, idProfile, uiProfile)
27+
const picture = _.get(profile, '_json.' + conf.pictureClaim, '')
2728

2829
try {
2930
const user = await WIKI.models.users.processProfile({
3031
providerKey: req.params.strategy,
3132
profile: {
3233
...profile,
3334
email: _.get(profile, '_json.' + conf.emailClaim),
34-
displayName: _.get(profile, '_json.' + conf.displayNameClaim, '')
35+
displayName: _.get(profile, '_json.' + conf.displayNameClaim, ''),
36+
picture: picture
3537
}
3638
})
3739
if (conf.mapGroups) {

server/modules/authentication/oidc/definition.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,33 @@ props:
6262
default: displayName
6363
maxWidth: 500
6464
order: 9
65+
pictureClaim:
66+
type: String
67+
title: Picture Claim
68+
hint: Field containing the user avatar URL
69+
default: picture
70+
maxWidth: 500
71+
order: 10
6572
mapGroups:
6673
type: Boolean
6774
title: Map Groups
6875
hint: Map groups matching names from the groups claim value
6976
default: false
70-
order: 10
77+
order: 11
7178
groupsClaim:
7279
type: String
7380
title: Groups Claim
7481
hint: Field containing the group names
7582
default: groups
7683
maxWidth: 500
77-
order: 11
84+
order: 12
7885
logoutURL:
7986
type: String
8087
title: Logout URL
8188
hint: (optional) Logout URL on the OAuth2 provider where the user will be redirected to complete the logout process.
82-
order: 12
89+
order: 13
8390
acrValues:
8491
type: String
8592
title: ACR Values
8693
hint: (optional) Authentication Context Class Reference
87-
order: 13
94+
order: 14

0 commit comments

Comments
 (0)