2019-08-23 13:58:04 +05:30
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace api\components\OAuth2\Repositories;
|
|
|
|
|
2019-09-22 02:47:21 +05:30
|
|
|
use api\components\OAuth2\Entities\RefreshTokenEntity;
|
|
|
|
use common\models\OauthRefreshToken;
|
2019-08-23 13:58:04 +05:30
|
|
|
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
|
|
|
|
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
|
2019-09-22 02:47:21 +05:30
|
|
|
use Webmozart\Assert\Assert;
|
2019-08-23 13:58:04 +05:30
|
|
|
|
|
|
|
class RefreshTokenRepository implements RefreshTokenRepositoryInterface {
|
|
|
|
|
2019-09-22 02:47:21 +05:30
|
|
|
public function getNewRefreshToken(): ?RefreshTokenEntityInterface {
|
|
|
|
return new RefreshTokenEntity();
|
2019-08-23 13:58:04 +05:30
|
|
|
}
|
|
|
|
|
2019-09-22 02:47:21 +05:30
|
|
|
public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity): void {
|
|
|
|
$model = new OauthRefreshToken();
|
|
|
|
$model->id = $refreshTokenEntity->getIdentifier();
|
|
|
|
$model->account_id = $refreshTokenEntity->getAccessToken()->getUserIdentifier();
|
|
|
|
$model->client_id = $refreshTokenEntity->getAccessToken()->getClient()->getIdentifier();
|
|
|
|
|
|
|
|
Assert::true($model->save());
|
2019-08-23 13:58:04 +05:30
|
|
|
}
|
|
|
|
|
2019-09-22 02:47:21 +05:30
|
|
|
public function revokeRefreshToken($tokenId): void {
|
|
|
|
// Currently we're not rotating refresh tokens so do not revoke
|
|
|
|
// token during any OAuth2 grant
|
2019-08-23 13:58:04 +05:30
|
|
|
}
|
|
|
|
|
2019-09-22 02:47:21 +05:30
|
|
|
public function isRefreshTokenRevoked($tokenId): bool {
|
2019-12-04 16:10:12 +05:30
|
|
|
return OauthRefreshToken::find()->andWhere(['id' => $tokenId])->exists() === false;
|
2019-08-23 13:58:04 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|