This repository has been archived by the owner on May 13, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbd8ad9
commit 40ea391
Showing
18 changed files
with
293 additions
and
136 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
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
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
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
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
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
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,85 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
/* | ||
* This file is part of the OAuth2 Client extension for TYPO3 | ||
* - (c) 2021 waldhacker UG (haftungsbeschränkt) | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace Waldhacker\Oauth2Client\Events\Listener; | ||
|
||
use TYPO3\CMS\Core\Authentication\Event\BeforeRequestTokenProcessedEvent; | ||
use TYPO3\CMS\Core\Context\Context; | ||
use TYPO3\CMS\Core\Security\RequestToken; | ||
use Waldhacker\Oauth2Client\Backend\LoginProvider\Oauth2LoginProvider; | ||
|
||
class GenerateRequestTokenListener | ||
{ | ||
public function __construct(protected readonly Context $context) | ||
{ | ||
} | ||
|
||
public function __invoke(BeforeRequestTokenProcessedEvent $event): void | ||
{ | ||
// todo | ||
// wenn oauth cookie => get time from token from cookie | ||
// wenn request within 5 sec => generate and set token | ||
|
||
// $requestToken = RequestToken::create('core/user-auth/be'); | ||
// $event->setRequestToken($requestToken); | ||
|
||
/* | ||
$request = $event->getRequest(); | ||
$getParameters = $request->getQueryParams(); | ||
$postParameters = is_array($request->getParsedBody()) ? $request->getParsedBody() : []; | ||
$loginProvider = $getParameters['loginProvider'] ?? null; | ||
if ($loginProvider !== Oauth2LoginProvider::PROVIDER_ID) { | ||
return; | ||
} | ||
$code = (string)($getParameters['code'] ?? ''); | ||
$state = (string)($getParameters['state'] ?? ''); | ||
$providerIdFromPost = (string)($postParameters['oauth2-provider'] ?? ''); | ||
$providerIdFromGet = (string)($getParameters['oauth2-provider'] ?? ''); | ||
$action = !empty($providerIdFromPost) && empty($code) && empty($state) | ||
? 'authorize' | ||
: (!empty($providerIdFromGet) && !empty($code) && !empty($state) ? 'verify' : 'invalid'); | ||
if ($action !== 'verify') { | ||
return; | ||
} | ||
$requestToken = $event->getRequestToken(); | ||
if (!($requestToken instanceof RequestToken)) { | ||
$event->setRequestToken(null); | ||
return; | ||
} | ||
// check time of request within 5 sec | ||
$now = $this->context->getAspect('date')->getDateTime(); | ||
$interval = new \DateInterval(sprintf('PT%dS', 5)); | ||
$moreThan5Seconds = $now > $requestToken->time->add($interval); | ||
if ($moreThan5Seconds) { | ||
$event->setRequestToken(null); | ||
return; | ||
} | ||
*/ | ||
} | ||
} |
Oops, something went wrong.