2016-11-30 01:45:56 +05:30
|
|
|
<?php
|
2019-09-22 02:47:21 +05:30
|
|
|
declare(strict_types=1);
|
2017-06-17 23:35:36 +05:30
|
|
|
|
2024-12-06 06:04:09 +05:30
|
|
|
namespace common\components\OAuth2\Grants;
|
2017-06-17 23:35:36 +05:30
|
|
|
|
2024-12-06 06:04:09 +05:30
|
|
|
use common\components\OAuth2\CryptTrait;
|
|
|
|
use common\components\OAuth2\Events\RequestedRefreshToken;
|
|
|
|
use common\components\OAuth2\Repositories\PublicScopeRepository;
|
2019-12-09 22:01:54 +05:30
|
|
|
use DateInterval;
|
2019-09-22 02:47:21 +05:30
|
|
|
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
|
2019-12-09 22:01:54 +05:30
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface;
|
2019-12-13 17:46:45 +05:30
|
|
|
use League\OAuth2\Server\Exception\OAuthServerException;
|
2019-09-22 02:47:21 +05:30
|
|
|
use League\OAuth2\Server\Grant\AuthCodeGrant as BaseAuthCodeGrant;
|
2019-12-13 17:46:45 +05:30
|
|
|
use League\OAuth2\Server\RequestEvent;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
use yii\helpers\StringHelper;
|
2017-06-17 23:35:36 +05:30
|
|
|
|
2024-12-06 06:04:09 +05:30
|
|
|
final class AuthCodeGrant extends BaseAuthCodeGrant {
|
2019-12-06 17:07:51 +05:30
|
|
|
use CryptTrait;
|
2017-06-17 23:35:36 +05:30
|
|
|
|
2019-12-09 22:01:54 +05:30
|
|
|
protected function issueAccessToken(
|
|
|
|
DateInterval $accessTokenTTL,
|
|
|
|
ClientEntityInterface $client,
|
2024-12-02 15:40:55 +05:30
|
|
|
?string $userIdentifier,
|
|
|
|
array $scopes = [],
|
2019-12-09 22:01:54 +05:30
|
|
|
): AccessTokenEntityInterface {
|
|
|
|
foreach ($scopes as $i => $scope) {
|
2019-09-22 02:47:21 +05:30
|
|
|
if ($scope->getIdentifier() === PublicScopeRepository::OFFLINE_ACCESS) {
|
2019-12-09 22:01:54 +05:30
|
|
|
unset($scopes[$i]);
|
2024-12-02 15:40:55 +05:30
|
|
|
$this->getEmitter()->emit(new RequestedRefreshToken('refresh_token_requested'));
|
2019-09-22 02:47:21 +05:30
|
|
|
}
|
2017-06-17 23:35:36 +05:30
|
|
|
}
|
|
|
|
|
2019-12-09 22:01:54 +05:30
|
|
|
return parent::issueAccessToken($accessTokenTTL, $client, $userIdentifier, $scopes);
|
2017-07-13 16:14:06 +05:30
|
|
|
}
|
|
|
|
|
2019-12-13 17:46:45 +05:30
|
|
|
protected function validateRedirectUri(
|
|
|
|
string $redirectUri,
|
|
|
|
ClientEntityInterface $client,
|
2024-12-02 15:40:55 +05:30
|
|
|
ServerRequestInterface $request,
|
2019-12-13 17:46:45 +05:30
|
|
|
): void {
|
|
|
|
$allowedRedirectUris = (array)$client->getRedirectUri();
|
|
|
|
foreach ($allowedRedirectUris as $allowedRedirectUri) {
|
|
|
|
if (StringHelper::startsWith($redirectUri, $allowedRedirectUri)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
|
|
|
|
throw OAuthServerException::invalidClient($request);
|
|
|
|
}
|
|
|
|
|
2016-11-30 01:45:56 +05:30
|
|
|
}
|