Skip to content

Commit

Permalink
Merge pull request #388 from bocharsky-bw/fix-cs
Browse files Browse the repository at this point in the history
Apply changes required by PHP CS Fixer and fix PHP 8.2 build
  • Loading branch information
bocharsky-bw authored Jan 31, 2023
2 parents d162e3d + 382d7a5 commit e343b87
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Client/OAuth2PKCEClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use League\OAuth2\Client\Provider\AbstractProvider;
use League\OAuth2\Client\Token\AccessToken;
use League\OAuth2\Client\Token\AccessTokenInterface;
use LogicException;
use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\RequestStack;
Expand Down Expand Up @@ -43,8 +42,7 @@ public function __construct(AbstractProvider $provider,
* PKCE code challenge and code challenge method parameters.
*
* @see OAuth2Client::redirect()
* @param array $scopes
* @param array $options
*
* @return RedirectResponse
*/
public function redirect(array $scopes = [], array $options = [])
Expand All @@ -60,34 +58,37 @@ public function redirect(array $scopes = [], array $options = [])

/**
* Enhance the token exchange calls by OAuth2Client::getAccessToken() with
* PKCE code verifier parameter
* PKCE code verifier parameter.
*
* @see OAuth2Client::getAccessToken()
* @param array $options
*
* @return AccessToken|AccessTokenInterface
* @throws LogicException When there is no code verifier found in the session
*
* @throws \LogicException When there is no code verifier found in the session
*/
public function getAccessToken(array $options = [])
{
if (!$this->getSession()->has(static::VERIFIER_KEY)) {
throw new LogicException('Unable to fetch token from OAuth2 server because there is no PKCE code verifier stored in the session');
throw new \LogicException('Unable to fetch token from OAuth2 server because there is no PKCE code verifier stored in the session');
}
$pkce = ['code_verifier' => $this->getSession()->get(static::VERIFIER_KEY)];
$this->getSession()->remove(static::VERIFIER_KEY);

return parent::getAccessToken($options + $pkce);
}

/**
* @return SessionInterface
* @throws LogicException When there is no current request
*
* @throws \LogicException When there is no current request
* @throws SessionNotFoundException When session is not set properly [thrown by Request::getSession()]
*/
protected function getSession()
{
$request = $this->requestStack->getCurrentRequest();

if (!$request) {
throw new LogicException('There is no "current request", and it is needed to perform this action');
throw new \LogicException('There is no "current request", and it is needed to perform this action');
}

return $request->getSession();
Expand Down
1 change: 1 addition & 0 deletions tests/Client/OAuth2PKCEClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
class OAuth2PKCEClientTest extends TestCase
{
private $requestStack;
private $request;
private $session;
private $provider;

Expand Down

0 comments on commit e343b87

Please sign in to comment.