Implemented more methods

This commit is contained in:
Alex Bilbie 2014-07-27 17:12:03 +01:00
parent 6cb5863b81
commit 29b09227ac
3 changed files with 59 additions and 15 deletions

View File

@ -73,7 +73,12 @@ class AccessTokenStorage extends Adapter implements AccessTokenInterface
*/
public function create($token, $expireTime, $sessionId)
{
die(var_dump(__METHOD__, func_get_args()));
Capsule::table('oauth_access_tokens')
->insert([
'access_token' => $token,
'session_id' => $sessionId,
'expire_time' => $expireTime
]);
}
/**

View File

@ -24,13 +24,14 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface
if (count($result) === 1) {
$token = new AuthCodeEntity($this->server);
$token->setId($result[0]['auth_code']);
$token->setRedirectUri($result[0]['client_redirect_uri']);
return $token;
}
return null;
}
public function create($token, $$expireTime, $sessionId)
public function create($token, $expireTime, $sessionId, $redirectUri)
{
Capsule::table('oauth_auth_codes')
->insert([
@ -46,7 +47,25 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface
*/
public function getScopes(AuthCodeEntity $token)
{
die(var_dump(__METHOD__, func_get_args()));
$result = Capsule::table('oauth_auth_code_scopes')
->select(['oauth_scopes.id', 'oauth_scopes.description'])
->join('oauth_scopes', 'oauth_auth_code_scopes.scope', '=', 'oauth_scopes.id')
->where('auth_code', $token->getId())
->get();
$response = [];
if (count($result) > 0) {
foreach ($result as $row) {
$scope = (new ScopeEntity($this->server))->hydrate([
'id' => $row['id'],
'description' => $row['description']
]);
$response[] = $scope;
}
}
return $response;
}
/**
@ -55,10 +74,10 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface
public function associateScope(AuthCodeEntity $token, ScopeEntity $scope)
{
Capsule::table('oauth_auth_code_scopes')
->insert([
'auth_code' => $token->getToken(),
'scope' => $scope->getId()
]);
->insert([
'auth_code' => $token->getId(),
'scope' => $scope->getId()
]);
}
/**
@ -66,6 +85,8 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface
*/
public function delete(AuthCodeEntity $token)
{
die(var_dump(__METHOD__, func_get_args()));
Capsule::table('oauth_auth_codes')
->where('auth_code', $token->getId())
->delete();
}
}

View File

@ -29,11 +29,10 @@ class SessionStorage extends Adapter implements SessionInterface
$result = Capsule::table('oauth_sessions')
->select(['oauth_sessions.id', 'oauth_sessions.owner_type', 'oauth_sessions.owner_id', 'oauth_sessions.client_id', 'oauth_sessions.client_redirect_uri'])
->join('oauth_access_tokens', 'oauth_access_tokens.session_id', '=', 'oauth_sessions.id')
->where('oauth_access_tokens.access_token', $accessToken->getToken())
->where('oauth_access_tokens.access_token', $accessToken->getId())
->get();
if (count($result) === 1) {
// die(var_dump($result));
$session = new SessionEntity($this->server);
$session->setId($result[0]['id']);
$session->setOwner($result[0]['owner_type'], $result[0]['owner_id']);
@ -49,7 +48,21 @@ class SessionStorage extends Adapter implements SessionInterface
*/
public function getByAuthCode(AuthCodeEntity $authCode)
{
die(var_dump(__METHOD__, func_get_args()));
$result = Capsule::table('oauth_sessions')
->select(['oauth_sessions.id', 'oauth_sessions.owner_type', 'oauth_sessions.owner_id', 'oauth_sessions.client_id', 'oauth_sessions.client_redirect_uri'])
->join('oauth_auth_codes', 'oauth_auth_codes.session_id', '=', 'oauth_sessions.id')
->where('oauth_auth_codes.auth_code', $authCode->getId())
->get();
if (count($result) === 1) {
$session = new SessionEntity($this->server);
$session->setId($result[0]['id']);
$session->setOwner($result[0]['owner_type'], $result[0]['owner_id']);
return $session;
}
return null;
}
/**
@ -67,9 +80,10 @@ class SessionStorage extends Adapter implements SessionInterface
$scopes = [];
foreach ($result as $scope) {
$scopes[] = (new ScopeEntity($this->server))
->setId($scope['id'])
->setDescription($scope['description']);
$scopes[] = (new ScopeEntity($this->server))->hydrate([
'id' => $scope['id'],
'description' => $scope['description']
]);
}
return $scopes;
@ -95,6 +109,10 @@ class SessionStorage extends Adapter implements SessionInterface
*/
public function associateScope(SessionEntity $session, ScopeEntity $scope)
{
die(var_dump(__CLASS__.'::'.__METHOD__, func_get_args()));
Capsule::table('oauth_session_scopes')
->insert([
'session_id' => $session->getId(),
'scope' => $scope->getId()
]);
}
}