Merge branch 'improve-oidc' into 'master'
oidc: Add roles claim and bound role See merge request framasoft/peertube/official-plugins!13
This commit is contained in:
		| @ -9,3 +9,5 @@ l'Éducation et de la Jeunesse" (french Ministry of National Education). | |||||||
|  |  | ||||||
| The callback URL to configure on the OIDC provider side is: <your-instance-url>/plugins/auth-openid-connect/router/code-cb | The callback URL to configure on the OIDC provider side is: <your-instance-url>/plugins/auth-openid-connect/router/code-cb | ||||||
| If you don't specifie a role attribute new users will have a 'User' role by default. If you use this attribute it should hold an integer from this set of values: 0 (Administrator), 1 (Moderator), 2 (User). | If you don't specifie a role attribute new users will have a 'User' role by default. If you use this attribute it should hold an integer from this set of values: 0 (Administrator), 1 (Moderator), 2 (User). | ||||||
|  |  | ||||||
|  | With `group-property` and `allowed-group` you can allow only a subset of users to login. | ||||||
|  | |||||||
| @ -94,6 +94,22 @@ async function register ({ | |||||||
|     private: true |     private: true | ||||||
|   }) |   }) | ||||||
|  |  | ||||||
|  |   registerSetting({ | ||||||
|  |     name: 'group-property', | ||||||
|  |     label: 'Group property', | ||||||
|  |     type: 'input', | ||||||
|  |     private: true, | ||||||
|  |     descriptionHTML: 'Property/claim that contains a users groups' | ||||||
|  |   }) | ||||||
|  |  | ||||||
|  |   registerSetting({ | ||||||
|  |     name: 'allowed-group', | ||||||
|  |     label: 'Allowed group', | ||||||
|  |     type: 'input', | ||||||
|  |     private: true, | ||||||
|  |     descriptionHTML: 'Will only allow login for users whose group array contains this group' | ||||||
|  |   }) | ||||||
|  |  | ||||||
|   const router = getRouter() |   const router = getRouter() | ||||||
|   router.use('/code-cb', (req, res) => handleCb(peertubeHelpers, settingsManager, req, res)) |   router.use('/code-cb', (req, res) => handleCb(peertubeHelpers, settingsManager, req, res)) | ||||||
|  |  | ||||||
| @ -249,7 +265,9 @@ async function handleCb (peertubeHelpers, settingsManager, req, res) { | |||||||
|       'mail-property', |       'mail-property', | ||||||
|       'username-property', |       'username-property', | ||||||
|       'display-name-property', |       'display-name-property', | ||||||
|       'role-property' |       'role-property', | ||||||
|  |       'group-property', | ||||||
|  |       'allowed-group' | ||||||
|     ]) |     ]) | ||||||
|  |  | ||||||
|     logger.debug('Got userinfo from openid auth.', { userInfo, settings }) |     logger.debug('Got userinfo from openid auth.', { userInfo, settings }) | ||||||
| @ -267,6 +285,16 @@ async function handleCb (peertubeHelpers, settingsManager, req, res) { | |||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     if (settings['group-property'] && settings['allowed-group']) { | ||||||
|  |       let roles = userInfo[settings['group-property']] | ||||||
|  |       if (!roles.includes(settings['allowed-group'])) { | ||||||
|  |         throw { | ||||||
|  |           name: "AllowedGroupNotFound", | ||||||
|  |           message: "User is not in allowed group" | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     let displayName |     let displayName | ||||||
|     if (settings['display-name-property']) { |     if (settings['display-name-property']) { | ||||||
|       displayName = userInfo[settings['display-name-property']] |       displayName = userInfo[settings['display-name-property']] | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user