2014-05-09 15:16:59 +05:30
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace RelationalExample\Storage;
|
|
|
|
|
2014-08-04 23:24:01 +05:30
|
|
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
2014-11-08 23:56:12 +05:30
|
|
|
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
|
|
|
use League\OAuth2\Server\Storage\Adapter;
|
|
|
|
use League\OAuth2\Server\Storage\RefreshTokenInterface;
|
2014-08-04 23:24:01 +05:30
|
|
|
|
2014-05-09 15:16:59 +05:30
|
|
|
class RefreshTokenStorage extends Adapter implements RefreshTokenInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function get($token)
|
|
|
|
{
|
2014-08-06 13:12:15 +05:30
|
|
|
$result = Capsule::table('oauth_refresh_tokens')
|
|
|
|
->where('refresh_token', $token)
|
|
|
|
->get();
|
|
|
|
|
|
|
|
if (count($result) === 1) {
|
|
|
|
$token = (new RefreshTokenEntity($this->server))
|
|
|
|
->setId($result[0]['refresh_token'])
|
|
|
|
->setExpireTime($result[0]['expire_time'])
|
|
|
|
->setAccessTokenId($result[0]['access_token']);
|
|
|
|
|
|
|
|
return $token;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2014-05-09 15:16:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function create($token, $expireTime, $accessToken)
|
|
|
|
{
|
2014-08-04 23:24:01 +05:30
|
|
|
Capsule::table('oauth_refresh_tokens')
|
|
|
|
->insert([
|
|
|
|
'refresh_token' => $token,
|
|
|
|
'access_token' => $accessToken,
|
2014-11-08 23:56:12 +05:30
|
|
|
'expire_time' => $expireTime,
|
2014-08-04 23:24:01 +05:30
|
|
|
]);
|
2014-05-09 15:16:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2014-05-23 20:55:09 +05:30
|
|
|
public function delete(RefreshTokenEntity $token)
|
2014-05-09 15:16:59 +05:30
|
|
|
{
|
2014-08-06 13:12:15 +05:30
|
|
|
Capsule::table('oauth_refresh_tokens')
|
|
|
|
->where('refresh_token', $token->getId())
|
|
|
|
->delete();
|
2014-05-09 15:16:59 +05:30
|
|
|
}
|
|
|
|
}
|