-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of the module ported from psul-web.
- Loading branch information
0 parents
commit 45129aa
Showing
5 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Development artifacts | ||
.DS_Store | ||
.vscode | ||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## INTRODUCTION | ||
|
||
The PSUL User Auth module is a alter user and authentication for PSU Library | ||
sites. | ||
|
||
The primary use case for this module is: | ||
|
||
- Ensure username set after authentication is NOT the email. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "psul-libraries/psul_user_auth", | ||
"description": "Adds functionality to alter users and user authentication", | ||
"type": "drupal-module", | ||
"license": "GPL-2.0-or-later", | ||
"authors": [ | ||
{ | ||
"name": "Mike Henninger", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"require": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: 'PSUL User Auth' | ||
type: module | ||
description: 'Adds functionality to alter users and user authentication' | ||
package: PSU Libraries | ||
core_version_requirement: ^10 || ^11 | ||
dependencies: | ||
- drupal:user | ||
- openid_connect:openid_connect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Primary module hooks for PSUL User Auth module. | ||
*/ | ||
|
||
/** | ||
* Implements hook_openid_connect_userinfo_alter(). | ||
* | ||
* Altering the following user data to ensure consist authentication. | ||
* - Email prevent user aliases from being used, | ||
* - Username (should NOT include '@psu.edu'), | ||
* - OIDC Name to include username (e.g. "Henninger, Mike (msh6004)"). | ||
* | ||
* All changes are based on the User.Identity.Name (UPN) value. | ||
*/ | ||
function psul_user_auth_openid_connect_userinfo_alter(array &$userinfo, array $context) { | ||
|
||
// Remove @psu.edu from the username. | ||
preg_match('/^(.+)@([^@]+)$/i', $userinfo['upn'], $matches); | ||
|
||
// Nothing else to do if the default email is not an email. | ||
if (!isset($matches[1])) { | ||
return; | ||
} | ||
|
||
// Forcing none alias email to be used. | ||
$userinfo['email'] = $userinfo['upn']; | ||
|
||
// Adding username to name so that users are unique. | ||
$userinfo['name'] .= " (" . $matches[1] . ")"; | ||
|
||
// Set the preferred username to strip out "@psu.edu". | ||
$userinfo['preferred_username'] = $matches[1]; | ||
} | ||
|
||
/** | ||
* Implements hook_user_format_name_alter(). | ||
*/ | ||
function psul_user_auth_user_format_name_alter(&$name, $account) { | ||
// Ensure that usernames are not displayed if they are email addresses, or if | ||
// they are generated names starting with 'oidc_'. | ||
$oidc_name = \Drupal::service('user.data')->get('openid_connect', $account->id(), 'oidc_name'); | ||
|
||
if (empty($oidc_name) || strpos($oidc_name, 'oidc_') === 0) { | ||
return; | ||
} | ||
|
||
// Always display the oidc_name if it is set. | ||
$name = $oidc_name; | ||
} |