-
Notifications
You must be signed in to change notification settings - Fork 114
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
f48d907
commit 79cc5cf
Showing
6 changed files
with
124 additions
and
2 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,55 @@ | ||
<?php | ||
|
||
namespace Trikoder\Bundle\OAuth2Bundle\Grant; | ||
|
||
use DateInterval; | ||
use League\OAuth2\Server\Entities\ClientEntityInterface; | ||
use League\OAuth2\Server\Grant\AuthCodeGrant as BaseAuthCodeGrant; | ||
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Trikoder\Bundle\OAuth2Bundle\League\Repository\AuthCodeRepository; | ||
use Trikoder\Bundle\OAuth2Bundle\OpenIDConnect\IdTokenResponse; | ||
|
||
/** | ||
* @property-read AuthCodeRepository $authCodeRepository | ||
*/ | ||
class AuthCodeGrant extends BaseAuthCodeGrant | ||
{ | ||
/** @var string|null */ | ||
private $nonce; | ||
|
||
public function validateAuthorizationRequest(ServerRequestInterface $request) | ||
{ | ||
$authorizationRequest = parent::validateAuthorizationRequest($request); | ||
|
||
$this->nonce = $this->getQueryStringParameter('nonce', $request, null); | ||
|
||
return $authorizationRequest; | ||
} | ||
|
||
protected function issueAuthCode(DateInterval $authCodeTTL, ClientEntityInterface $client, $userIdentifier, $redirectUri, array $scopes = []) | ||
{ | ||
$autCode = parent::issueAuthCode($authCodeTTL, $client, $userIdentifier, $redirectUri, $scopes); | ||
|
||
if ($this->nonce !== null) { | ||
$this->authCodeRepository->updateWithNonce($autCode, $this->nonce); | ||
} | ||
|
||
return $autCode; | ||
} | ||
|
||
public function respondToAccessTokenRequest(ServerRequestInterface $request, ResponseTypeInterface $responseType, DateInterval $accessTokenTTL) | ||
{ | ||
$response = parent::respondToAccessTokenRequest($request, $responseType, $accessTokenTTL); | ||
|
||
if ($response instanceof IdTokenResponse) { | ||
$encryptedAuthCode = $this->getRequestParameter('code', $request, null); | ||
$authCodePayload = json_decode($this->decrypt($encryptedAuthCode)); | ||
|
||
$nonce = $this->authCodeRepository->getNonce($authCodePayload->auth_code_id); | ||
$response->setNonce($nonce); | ||
} | ||
|
||
return $response; | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace Trikoder\Bundle\OAuth2Bundle\OpenIDConnect; | ||
|
||
use League\OAuth2\Server\Entities\AccessTokenEntityInterface; | ||
use League\OAuth2\Server\Entities\UserEntityInterface; | ||
use OpenIDConnectServer\IdTokenResponse as BaseIdTokenResponse; | ||
|
||
class IdTokenResponse extends BaseIdTokenResponse | ||
{ | ||
/** @var string|null */ | ||
private $nonce; | ||
|
||
public function setNonce(string $nonce) | ||
{ | ||
$this->nonce = $nonce; | ||
} | ||
|
||
protected function getBuilder(AccessTokenEntityInterface $accessToken, UserEntityInterface $userEntity) | ||
{ | ||
$builder = parent::getBuilder($accessToken, $userEntity); | ||
|
||
if (null !== $this->nonce) { | ||
$builder->set('nonce', $this->nonce); | ||
} | ||
|
||
return $builder; | ||
} | ||
} |
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