-
-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: removed own UUID v4 implementation and add Symfony UID Component
- Loading branch information
Showing
4 changed files
with
173 additions
and
36 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,14 +1,29 @@ | ||
<?php | ||
|
||
/** | ||
* Session class for Entra ID. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ | ||
* @author Thorsten Rinne <[email protected]> | ||
* @copyright 2024 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2024-11-02 | ||
*/ | ||
|
||
namespace phpMyFAQ\Auth\EntraId; | ||
|
||
use Exception; | ||
use phpMyFAQ\Configuration; | ||
use phpMyFAQ\Session\AbstractSession; | ||
use Random\RandomException; | ||
use Symfony\Component\HttpFoundation\Cookie; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Session\Session as SymfonySession; | ||
use Symfony\Component\Uid\Uuid; | ||
|
||
class Session extends AbstractSession | ||
{ | ||
|
@@ -35,7 +50,7 @@ public function __construct(private readonly Configuration $configuration, priva | |
*/ | ||
public function createCurrentSessionKey(): void | ||
{ | ||
$this->currentSessionKey = $this->uuid(); | ||
$this->currentSessionKey = Uuid::v4(); | ||
} | ||
|
||
/** | ||
|
@@ -94,27 +109,4 @@ public function getCookie(string $name): string | |
$request = Request::createFromGlobals(); | ||
return $request->cookies->get($name, ''); | ||
} | ||
|
||
/** | ||
* Returns a UUID Version 4 compatible universally unique identifier. | ||
*/ | ||
public function uuid(): string | ||
{ | ||
try { | ||
return sprintf( | ||
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x', | ||
random_int(0, 0xffff), | ||
random_int(0, 0xffff), | ||
random_int(0, 0xffff), | ||
random_int(0, 0x0fff) | 0x4000, | ||
random_int(0, 0x3fff) | 0x8000, | ||
random_int(0, 0xffff), | ||
random_int(0, 0xffff), | ||
random_int(0, 0xffff) | ||
); | ||
} catch (RandomException $e) { | ||
$this->configuration->getLogger()->error('Cannot generate UUID: ' . $e->getMessage()); | ||
return ''; | ||
} | ||
} | ||
} |
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