Fixed issues with returns and columns

This commit is contained in:
Daniel Schniepp 2013-09-25 16:59:45 +02:00
parent bee71c1e83
commit 23627c659e
3 changed files with 108 additions and 103 deletions

View File

@ -7,26 +7,32 @@ use \League\OAuth2\Server\Storage\ClientInterface;
class Client implements ClientInterface { class Client implements ClientInterface {
public function getClient($clientId, $clientSecret = null, $redirectUri = null, $grantType = null) public function getClient($clientId, $clientSecret = null, $redirectUri = null, $grantType = null) {
{
if (!is_null($redirectUri) && is_null($clientSecret)) { if (!is_null($redirectUri) && is_null($clientSecret)) {
$result = DB::table('oauth_clients') $result = DB::table('oauth_clients')
->join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id') ->join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id')
->where('oauth_clients.id', $clientId) ->where('oauth_clients.id', $clientId)
->where('oauth_client_endpoints.redirect_uri', $redirectUri) ->where('oauth_client_endpoints.redirect_uri', $redirectUri)
->first(); ->first();
} elseif (!is_null($clientSecret) && is_null($redirectUri)) { } elseif (!is_null($clientSecret) && is_null($redirectUri)) {
$result = DB::table('oauth_clients') $result = DB::table('oauth_clients')
->where('id', $clientId) ->where('id', $clientId)
->where('secret', $clientSecret) ->where('secret', $clientSecret)
->first(); ->first();
} elseif (!is_null($clientSecret) && !is_null($redirectUri)) { } elseif (!is_null($clientSecret) && !is_null($redirectUri)) {
$queries = DB::getQueryLog();
$result = DB::table('oauth_clients') $result = DB::table('oauth_clients')
->join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id') ->join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id')
->where('oauth_clients.id', $clientId) ->where('oauth_clients.id', $clientId)
->where('oauth_clients.secret', $clientSecret) ->where('oauth_clients.secret', $clientSecret)
->where('oauth_client_endpoints.redirect_uri', $redirectUri) ->where('oauth_client_endpoints.redirect_uri', $redirectUri)
->first(); ->first();
} }
if (is_null($result)) { if (is_null($result)) {
@ -37,7 +43,8 @@ class Client implements ClientInterface {
'client_id' => $result->id, 'client_id' => $result->id,
'client_secret' => $result->secret, 'client_secret' => $result->secret,
'redirect_uri' => (isset($result->redirect_uri)) ? $result->redirect_uri : null, 'redirect_uri' => (isset($result->redirect_uri)) ? $result->redirect_uri : null,
'name' => $result->name 'name' => $result->name,
'auto_approve' => $result->auto_approve
); );
} }

View File

@ -7,10 +7,9 @@ use \League\OAuth2\Server\Storage\ScopeInterface;
class Scope implements ScopeInterface { class Scope implements ScopeInterface {
public function getScope($scope, $clientId = null, $grantType = null) public function getScope($scope, $clientId = null, $grantType = null) {
{
$result = DB::table('oauth_scopes') $result = DB::table('oauth_scopes')
->where('key', $scope) ->where('scope', $scope)
->first(); ->first();
if (is_null($result)) { if (is_null($result)) {
@ -19,9 +18,10 @@ class Scope implements ScopeInterface {
return array( return array(
'id' => $result->id, 'id' => $result->id,
'scope' => $result->key, 'scope' => $result->scope,
'name' => $result->name, 'name' => $result->name,
'description' => $result->description 'description' => $result->description
); );
} }
} }

View File

@ -7,17 +7,15 @@ use \League\OAuth2\Server\Storage\SessionInterface;
class Session implements SessionInterface { class Session implements SessionInterface {
public function createSession($clientId, $ownerType, $ownerId) public function createSession($clientId, $ownerType, $ownerId) {
{ return DB::table('oauth_sessions')->insertGetId([
return DB::table('oauth_sessions')->insertGetId(array(
'client_id' => $clientId, 'client_id' => $clientId,
'owner_type' => $ownerType, 'owner_type' => $ownerType,
'owner_id' => $ownerId 'owner_id' => $ownerId
)); ]);
} }
public function deleteSession($clientId, $ownerType, $ownerId) public function deleteSession($clientId, $ownerType, $ownerId) {
{
DB::table('oauth_sessions') DB::table('oauth_sessions')
->where('client_id', $clientId) ->where('client_id', $clientId)
->where('owner_type', $ownerType) ->where('owner_type', $ownerType)
@ -25,53 +23,52 @@ class Session implements SessionInterface {
->delete(); ->delete();
} }
public function associateRedirectUri($sessionId, $redirectUri) public function associateRedirectUri($sessionId, $redirectUri) {
{ DB::table('oauth_session_redirects')->insert([
DB::table('oauth_session_redirects')->insert(array(
'session_id' => $sessionId, 'session_id' => $sessionId,
'redirect_uri' => $redirectUri, 'redirect_uri' => $redirectUri,
)); ]);
} }
public function associateAccessToken($sessionId, $accessToken, $expireTime) public function associateAccessToken($sessionId, $accessToken, $expireTime) {
{ return DB::table('oauth_session_access_tokens')->insertGetId([
return DB::table('oauth_session_access_tokens')->insertGetId(array(
'session_id' => $sessionId, 'session_id' => $sessionId,
'access_token' => $accessToken, 'access_token' => $accessToken,
'access_token_expires' => $expireTime, 'access_token_expires' => $expireTime,
)); ]);
} }
public function associateRefreshToken($accessTokenId, $refreshToken, $expireTime, $clientId) public function associateRefreshToken($accessTokenId, $refreshToken, $expireTime, $clientId) {
{ DB::table('oauth_session_refresh_tokens')->insert([
DB::table('oauth_session_refresh_tokens')->insert(array(
'session_access_token_id' => $accessTokenId, 'session_access_token_id' => $accessTokenId,
'refresh_token' => $refreshToken, 'refresh_token' => $refreshToken,
'refresh_token_expires' => $expireTime, 'refresh_token_expires' => $expireTime,
'client_id' => $clientId, 'client_id' => $clientId,
)); ]);
} }
public function associateAuthCode($sessionId, $authCode, $expireTime) public function associateAuthCode($sessionId, $authCode, $expireTime) {
{
DB::table('oauth_session_authcodes')->insert(array(
DB::table('oauth_session_authcodes')->insert([
'session_id' => $sessionId, 'session_id' => $sessionId,
'auth_code' => $authCode, 'auth_code' => $authCode,
'auth_code_expires' => $expireTime 'auth_code_expires' => $expireTime
)); ]);
return DB::table('oauth_session_authcodes')->where('auth_code',$authCode)->first()->id;
} }
public function removeAuthCode($sessionId) public function removeAuthCode($sessionId) {
{
DB::table('oauth_session_authcodes') DB::table('oauth_session_authcodes')
->where('session_id', $sessionId) ->where('session_id', $sessionId)
->delete(); ->delete();
} }
public function validateAuthCode($clientId, $redirectUri, $authCode) public function validateAuthCode($clientId, $redirectUri, $authCode) {
{
$result = DB::table('oauth_sessions') $result = DB::table('oauth_sessions')
->select(array('oauth_sessions.id as session_id', 'oauth_session_authcodes.id as authcode_id')) ->select(['oauth_sessions.id as session_id', 'oauth_session_authcodes.id as authcode_id'])
->join('oauth_session_authcodes', 'oauth_sessions.id', '=', 'oauth_session_authcodes.session_id') ->join('oauth_session_authcodes', 'oauth_sessions.id', '=', 'oauth_session_authcodes.session_id')
->join('oauth_session_redirects', 'oauth_sessions.id', '=', 'oauth_session_redirects.session_id') ->join('oauth_session_redirects', 'oauth_sessions.id', '=', 'oauth_session_redirects.session_id')
->where('oauth_sessions.client_id', $clientId) ->where('oauth_sessions.client_id', $clientId)
@ -83,8 +80,7 @@ class Session implements SessionInterface {
return (is_null($result)) ? false : (array) $result; return (is_null($result)) ? false : (array) $result;
} }
public function validateAccessToken($accessToken) public function validateAccessToken($accessToken) {
{
$result = DB::table('oauth_session_access_tokens') $result = DB::table('oauth_session_access_tokens')
->join('oauth_sessions', 'oauth_session_access_tokens.session_id', '=', 'oauth_sessions.id') ->join('oauth_sessions', 'oauth_session_access_tokens.session_id', '=', 'oauth_sessions.id')
->where('access_token', $accessToken) ->where('access_token', $accessToken)
@ -94,8 +90,7 @@ class Session implements SessionInterface {
return (is_null($result)) ? false : (array) $result; return (is_null($result)) ? false : (array) $result;
} }
public function validateRefreshToken($refreshToken, $clientId) public function validateRefreshToken($refreshToken, $clientId) {
{
$result = DB::table('oauth_session_refresh_tokens') $result = DB::table('oauth_session_refresh_tokens')
->where('refresh_token', $refreshToken) ->where('refresh_token', $refreshToken)
->where('client_id', $clientId) ->where('client_id', $clientId)
@ -105,8 +100,7 @@ class Session implements SessionInterface {
return (is_null($result)) ? false : $result->session_access_token_id; return (is_null($result)) ? false : $result->session_access_token_id;
} }
public function getAccessToken($accessTokenId) public function getAccessToken($accessTokenId) {
{
$result = DB::table('oauth_session_access_tokens') $result = DB::table('oauth_session_access_tokens')
->where('id', $accessTokenId) ->where('id', $accessTokenId)
->first(); ->first();
@ -114,16 +108,17 @@ class Session implements SessionInterface {
return (is_null($result)) ? false : (array) $result; return (is_null($result)) ? false : (array) $result;
} }
public function associateScope($accessTokenId, $scopeId) public function associateScope($accessTokenId, $scopeId) {
{
DB::table('oauth_session_token_scopes')->insert(array(
DB::table('oauth_session_token_scopes')->insert([
'session_access_token_id' => $accessTokenId, 'session_access_token_id' => $accessTokenId,
'scope_id' => $scopeId, 'scope_id' => $scopeId,
)); ]);
} }
public function getScopes($accessToken) public function getScopes($accessToken) {
{
return DB::table('oauth_session_token_scopes') return DB::table('oauth_session_token_scopes')
->join('oauth_session_access_tokens', 'oauth_session_token_scopes.session_access_token_id', '=', 'oauth_session_access_tokens.id') ->join('oauth_session_access_tokens', 'oauth_session_token_scopes.session_access_token_id', '=', 'oauth_session_access_tokens.id')
->join('oauth_scopes', 'oauth_session_token_scopes.session_access_token_id', '=', 'oauth_scopes.id') ->join('oauth_scopes', 'oauth_session_token_scopes.session_access_token_id', '=', 'oauth_scopes.id')
@ -131,23 +126,26 @@ class Session implements SessionInterface {
->get(); ->get();
} }
public function associateAuthCodeScope($authCodeId, $scopeId) public function associateAuthCodeScope($authCodeId, $scopeId) {
{
DB::table('oauth_session_authcode_scopes')->insert(array( DB::table('oauth_session_authcode_scopes')->insert([
'oauth_session_authcode_id' => $authCodeId, 'oauth_session_authcode_id' => $authCodeId,
'scope_id' => $scopeId 'scope_id' => $scopeId
)); ]);
} }
public function getAuthCodeScopes($oauthSessionAuthCodeId) public function getAuthCodeScopes($oauthSessionAuthCodeId) {
{ $result = DB::table('oauth_session_authcode_scopes')
return DB::table('oauth_session_authcode_scopes')
->where('oauth_session_authcode_id', '=', $oauthSessionAuthCodeId) ->where('oauth_session_authcode_id', '=', $oauthSessionAuthCodeId)
->get(); ->get();
return array_map(function($val)
{
return json_decode(json_encode($val), true);
}, $result);
} }
public function removeRefreshToken($refreshToken) public function removeRefreshToken($refreshToken) {
{
DB::table('oauth_session_refresh_tokens') DB::table('oauth_session_refresh_tokens')
->where('refresh_token', '=', $refreshToken) ->where('refresh_token', '=', $refreshToken)
->delete(); ->delete();