Skip to content

Commit

Permalink
UHF-9458: Use Uuid:isValid()
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrsky committed Jan 9, 2024
1 parent a0597ce commit 45015e4
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions helfi_tunnistamo.module
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

declare(strict_types = 1);

use Drupal\Component\Uuid\Uuid;
use Drupal\Core\Form\FormStateInterface;
use Drupal\helfi_tunnistamo\Plugin\OpenIDConnectClient\Tunnistamo;
use Drupal\openid_connect\Entity\OpenIDConnectClientEntity;
Expand Down Expand Up @@ -78,10 +79,7 @@ function helfi_tunnistamo_openid_connect_userinfo_alter(

// Unset preferred_username if it is a UUID so that new users get their
// name from `name` field instead.
if (
!empty($userinfo['preferred_username'])
&& preg_match('/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/', $userinfo['preferred_username'])
) {
if (!empty($userinfo['preferred_username']) && Uuid::isValid($userinfo['preferred_username'])) {
unset($userinfo['preferred_username']);
}

Expand Down

0 comments on commit 45015e4

Please sign in to comment.