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
|
|
|
|
2019-09-22 02:47:21 +05:30
|
|
|
namespace api\components\OAuth2\Grants;
|
2017-06-17 23:35:36 +05:30
|
|
|
|
2019-12-06 17:07:51 +05:30
|
|
|
use api\components\OAuth2\CryptTrait;
|
2019-12-09 22:01:54 +05:30
|
|
|
use api\components\OAuth2\Events\RequestedRefreshToken;
|
2019-09-22 02:47:21 +05:30
|
|
|
use api\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
|
|
|
|
2019-09-22 02:47:21 +05:30
|
|
|
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
|
|
|
/**
|
|
|
|
* @param DateInterval $accessTokenTTL
|
|
|
|
* @param ClientEntityInterface $client
|
|
|
|
* @param string|null $userIdentifier
|
|
|
|
* @param \League\OAuth2\Server\Entities\ScopeEntityInterface[] $scopes
|
|
|
|
*
|
|
|
|
* @return AccessTokenEntityInterface
|
|
|
|
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
|
|
|
* @throws \League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException
|
|
|
|
*/
|
|
|
|
protected function issueAccessToken(
|
|
|
|
DateInterval $accessTokenTTL,
|
|
|
|
ClientEntityInterface $client,
|
|
|
|
$userIdentifier,
|
|
|
|
array $scopes = []
|
|
|
|
): 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]);
|
|
|
|
$this->getEmitter()->emit(new RequestedRefreshToken());
|
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,
|
|
|
|
ServerRequestInterface $request
|
|
|
|
): 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
|
|
|
}
|