Skip to content
Snippets Groups Projects

WP110 #1191: Updated the uib_feide module to consume groups from Feide

Merged Are Johannessen requested to merge 1191-uib-feide-should-consume-groups-from-FEIDE into master
1 file
+ 15
9
Compare changes
  • Side-by-side
  • Inline
+ 15
9
@@ -8,9 +8,6 @@
@@ -8,9 +8,6 @@
* Feide OpenID connection.
* Feide OpenID connection.
*/
*/
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\user\UserInterface;
/**
/**
* Implements hook_openid_connect_userinfo_alter().
* Implements hook_openid_connect_userinfo_alter().
*/
*/
@@ -22,11 +19,11 @@ function uib_feide_openid_connect_userinfo_alter(#[\SensitiveParameter] array &$
@@ -22,11 +19,11 @@ function uib_feide_openid_connect_userinfo_alter(#[\SensitiveParameter] array &$
'GET',
'GET',
'https://api.dataporten.no/userinfo/v1/userinfo',
'https://api.dataporten.no/userinfo/v1/userinfo',
['headers' => ['Authorization' => 'Bearer ' . $context['tokens']['access_token']]]);
['headers' => ['Authorization' => 'Bearer ' . $context['tokens']['access_token']]]);
$extUserInfo = json_decode($response->getBody(), true);
$extUserInfo = json_decode($response->getBody(), TRUE);
$userinfo['groups'] = [];
$userinfo['groups'] = [];
if (count($extUserInfo) > 1 && isset($extUserInfo['eduPersonEntitlement'])) {
if (count($extUserInfo) > 1 && isset($extUserInfo['eduPersonEntitlement'])) {
foreach ($extUserInfo['eduPersonEntitlement'] as $group) {
foreach ($extUserInfo['eduPersonEntitlement'] as $group) {
$userinfo['groups'][] = Roles::from($group)->name;
$userinfo['groups'][] = Roles::{Roles::from($group)->name}->getRole();
}
}
}
}
}
}
@@ -54,9 +51,18 @@ function uib_feide_openid_connect_pre_authorize($account, array $context) : bool
@@ -54,9 +51,18 @@ function uib_feide_openid_connect_pre_authorize($account, array $context) : bool
return TRUE;
return TRUE;
}
}
enum Roles: string
/**
{
* Enum maintaining drupal roles and the associated group definitions in FEIDE.
case study_program_contributor = 'https://api.uib.no/names/roles/eksternweb/uibno_studies_and_students_author';
*/
case study_program_editor = 'https://api.uib.no/names/roles/eksternweb/uibno_studies_and_students_manager';
enum Roles: string {
 
case StudyProgramContributor = 'https://api.uib.no/names/roles/eksternweb/uibno_studies_and_students_author';
 
case StudyProgramEditor = 'https://api.uib.no/names/roles/eksternweb/uibno_studies_and_students_manager';
 
 
public function getRole(): string {
 
return match ($this) {
 
Roles::StudyProgramContributor => 'study_program_contributor',
 
Roles::StudyProgramEditor => 'study_program_editor',
 
};
 
}
}
}
Loading