2016-02-14 23:20:10 +05:30
|
|
|
<?php
|
2016-11-27 03:13:42 +05:30
|
|
|
namespace api\components\OAuth2\Storage;
|
2016-02-14 23:20:10 +05:30
|
|
|
|
2016-11-29 04:27:58 +05:30
|
|
|
use api\components\OAuth2\Entities\RefreshTokenEntity;
|
2016-11-27 20:11:39 +05:30
|
|
|
use common\components\Redis\Key;
|
2016-11-29 04:27:58 +05:30
|
|
|
use League\OAuth2\Server\Entity\RefreshTokenEntity as OriginalRefreshTokenEntity;
|
2016-02-14 23:20:10 +05:30
|
|
|
use League\OAuth2\Server\Storage\AbstractStorage;
|
|
|
|
use League\OAuth2\Server\Storage\RefreshTokenInterface;
|
|
|
|
|
|
|
|
class RefreshTokenStorage extends AbstractStorage implements RefreshTokenInterface {
|
|
|
|
|
|
|
|
public $dataTable = 'oauth_refresh_tokens';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function get($token) {
|
2016-11-29 04:27:58 +05:30
|
|
|
$result = json_decode((new Key($this->dataTable, $token))->getValue(), true);
|
2016-02-14 23:20:10 +05:30
|
|
|
if (!$result) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-11-27 03:13:42 +05:30
|
|
|
$entity = new RefreshTokenEntity($this->server);
|
|
|
|
$entity->setId($result['id']);
|
|
|
|
$entity->setAccessTokenId($result['access_token_id']);
|
|
|
|
|
|
|
|
return $entity;
|
2016-02-14 23:20:10 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function create($token, $expireTime, $accessToken) {
|
|
|
|
$payload = [
|
|
|
|
'id' => $token,
|
|
|
|
'access_token_id' => $accessToken,
|
|
|
|
];
|
|
|
|
|
|
|
|
(new Key($this->dataTable, $token))->setValue($payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2016-11-29 04:27:58 +05:30
|
|
|
public function delete(OriginalRefreshTokenEntity $token) {
|
2016-02-14 23:20:10 +05:30
|
|
|
(new Key($this->dataTable, $token->getId()))->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|