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

72 lines
1.9 KiB
PHP
Raw Normal View History

2014-05-09 15:16:59 +05:30
<?php
namespace RelationalExample\Storage;
use League\OAuth2\Server\Storage\AuthCodeInterface;
use League\OAuth2\Server\Storage\Adapter;
2014-05-23 20:55:09 +05:30
use League\OAuth2\Server\Entity\AuthCodeEntity;
use League\OAuth2\Server\Entity\ScopeEntity;
2014-05-09 15:16:59 +05:30
2014-06-23 12:50:34 +05:30
use Illuminate\Database\Capsule\Manager as Capsule;
2014-05-09 15:16:59 +05:30
class AuthCodeStorage extends Adapter implements AuthCodeInterface
{
/**
* {@inheritdoc}
*/
2014-05-23 20:55:09 +05:30
public function get($code)
{
2014-06-23 12:50:34 +05:30
$result = Capsule::table('oauth_auth_codes')
->where('auth_code', $code)
->where('expire_time', '>=', time())
->get();
if (count($result) === 1) {
$token = new AuthCodeEntity($this->server);
$token->setToken($result[0]['auth_code']);
return $token;
}
return null;
}
public function create($token, $$expireTime, $sessionId)
{
Capsule::table('oauth_auth_codes')
->insert([
'auth_code' => $token,
'client_redirect_uri' => $redirectUri,
'session_id' => $sessionId,
'expire_time' => $expireTime
]);
2014-05-23 20:55:09 +05:30
}
/**
* {@inheritdoc}
*/
public function getScopes(AuthCodeEntity $token)
{
die(var_dump(__METHOD__, func_get_args()));
}
/**
* {@inheritdoc}
*/
public function associateScope(AuthCodeEntity $token, ScopeEntity $scope)
{
2014-06-23 12:50:34 +05:30
Capsule::table('oauth_auth_code_scopes')
->insert([
'auth_code' => $token->getToken(),
'scope' => $scope->getId()
]);
2014-05-23 20:55:09 +05:30
}
/**
* {@inheritdoc}
*/
public function delete(AuthCodeEntity $token)
2014-05-09 15:16:59 +05:30
{
die(var_dump(__METHOD__, func_get_args()));
}
}