oauth2-server/examples/relational/Storage/RefreshTokenStorage.php

58 lines
1.5 KiB
PHP
Raw Normal View History

2014-05-09 15:16:59 +05:30
<?php
namespace RelationalExample\Storage;
use League\OAuth2\Server\Storage\RefreshTokenInterface;
use League\OAuth2\Server\Storage\Adapter;
2014-05-23 20:55:09 +05:30
use League\OAuth2\Server\Entity\RefreshTokenEntity;
2014-05-09 15:16:59 +05:30
2014-08-04 23:24:01 +05:30
use Illuminate\Database\Capsule\Manager as Capsule;
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,
'expire_time' => $expireTime
]);
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
}
2014-05-23 20:55:09 +05:30
2014-05-09 15:16:59 +05:30
}