From 94a064e2f46f9a1d6f35c6a7510844129c36dbb4 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Tue, 14 May 2013 09:44:12 +0100 Subject: [PATCH 01/10] Added fluent storage from #54 --- .../OAuth2/Server/Storage/Fluent/Client.php | 45 ++++ .../OAuth2/Server/Storage/Fluent/Scope.php | 25 +++ .../OAuth2/Server/Storage/Fluent/Session.php | 210 ++++++++++++++++++ 3 files changed, 280 insertions(+) create mode 100644 src/League/OAuth2/Server/Storage/Fluent/Client.php create mode 100644 src/League/OAuth2/Server/Storage/Fluent/Scope.php create mode 100644 src/League/OAuth2/Server/Storage/Fluent/Session.php diff --git a/src/League/OAuth2/Server/Storage/Fluent/Client.php b/src/League/OAuth2/Server/Storage/Fluent/Client.php new file mode 100644 index 00000000..8c8d5a2c --- /dev/null +++ b/src/League/OAuth2/Server/Storage/Fluent/Client.php @@ -0,0 +1,45 @@ +join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id') + ->where('oauth_clients.id', $clientId) + ->where('oauth_client_endpoints.redirect_uri', $redirectUri) + ->first(); + } + + elseif ( ! is_null($clientSecret) && is_null($redirectUri)) { + $result = DB::table('oauth_clients') + ->where('id', $clientId) + ->where('secret', $clientSecret) + ->first(); + } + + elseif ( ! is_null($clientSecret) && ! is_null($redirectUri)) { + $result = DB::table('oauth_clients') + ->join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id') + ->where('oauth_clients.id', $clientId) + ->where('oauth_clients.secret', $clientSecret) + ->where('oauth_client_endpoints.redirect_uri', $redirectUri) + ->first(); + } + + if (is_null($result)) { + return false; + } + + return array( + 'client_id' => $result->id, + 'client_secret' => $result->secret, + 'redirect_uri' => (isset($result->redirect_uri)) ? $result->redirect_uri : null, + 'name' => $result->name + ); + } + +} \ No newline at end of file diff --git a/src/League/OAuth2/Server/Storage/Fluent/Scope.php b/src/League/OAuth2/Server/Storage/Fluent/Scope.php new file mode 100644 index 00000000..ff99660b --- /dev/null +++ b/src/League/OAuth2/Server/Storage/Fluent/Scope.php @@ -0,0 +1,25 @@ +where('key', $scope) + ->first(); + + if (is_null($result)) { + return false; + } + + return array( + 'id' => $result->id, + 'scope' => $result->key, + 'name' => $result->name, + 'description' => $result->description + ); + } + +} \ No newline at end of file diff --git a/src/League/OAuth2/Server/Storage/Fluent/Session.php b/src/League/OAuth2/Server/Storage/Fluent/Session.php new file mode 100644 index 00000000..4a235614 --- /dev/null +++ b/src/League/OAuth2/Server/Storage/Fluent/Session.php @@ -0,0 +1,210 @@ +insertGetId([ + 'client_id' => $clientId, + 'owner_type' => $ownerType, + 'owner_id' => $ownerId + ]); + } + + /** + * Delete a session + * @param string $clientId The client ID + * @param string $ownerType The type of the session owner (e.g. "user") + * @param string $ownerId The ID of the session owner (e.g. "123") + * @return void + */ + public function deleteSession($clientId, $ownerType, $ownerId) + { + DB::table('oauth_sessions') + ->where('client_id', $clientId) + ->where('owner_type', $ownerType) + ->where('owner_id', $ownerId) + ->delete(); + } + + /** + * Associate a redirect URI with a session + * @param int $sessionId The session ID + * @param string $redirectUri The redirect URI + * @return void + */ + public function associateRedirectUri($sessionId, $redirectUri) + { + DB::table('oauth_session_redirects')->insert([ + 'session_id' => $sessionId, + 'redirect_uri' => $redirectUri, + ]); + } + + /** + * Associate an access token with a session + * @param int $sessionId The session ID + * @param string $accessToken The access token + * @param int $expireTime Unix timestamp of the access token expiry time + * @return int + */ + public function associateAccessToken($sessionId, $accessToken, $expireTime) + { + return DB::table('oauth_session_access_tokens')->insertGetId([ + 'session_id' => $sessionId, + 'access_token' => $accessToken, + 'access_token_expires' => $expireTime, + ]); + } + + /** + * Associate a refresh token with a session + * @param int $accessTokenId The access token ID + * @param string $refreshToken The refresh token + * @return void + */ + public function associateRefreshToken($accessTokenId, $refreshToken, $expireTime, $clientId) + { + DB::table('oauth_session_refresh_tokens')->insert([ + 'session_access_token_id' => $accessTokenId, + 'refresh_token' => $refreshToken, + 'refresh_token_expires' => $expireTime, + 'client_id' => $clientId, + ]); + } + + /** + * Assocate an authorization code with a session + * @param int $sessionId The session ID + * @param string $authCode The authorization code + * @param int $expireTime Unix timestamp of the access token expiry time + * @param string $scopeIds Comma seperated list of scope IDs to be later associated (default = null) + * @return void + */ + public function associateAuthCode($sessionId, $authCode, $expireTime, $scopeIds = null) + { + DB::table('oauth_session_authcodes')->insert([ + 'session_id' => $sessionId, + 'auth_code' => $authCode, + 'auth_code_expires' => $expireTime, + 'scope_ids' => $scopeIds, + ]); + } + + /** + * Remove an associated authorization token from a session + * @param int $sessionId The session ID + * @return void + */ + public function removeAuthCode($sessionId) + { + DB::table('oauth_session_authcodes') + ->where('session_id', $sessionId) + ->delete(); + } + + /** + * Validate an authorization code + * @param string $clientId The client ID + * @param string $redirectUri The redirect URI + * @param string $authCode The authorization code + * @return void + */ + public function validateAuthCode($clientId, $redirectUri, $authCode) + { + $result = DB::table('oauth_sessions') + ->select('oauth_sessions.id, oauth_session_authcodes.scope_ids') + ->join('oauth_session_authcodes', 'oauth_sessions.id', '=', 'oauth_session_authcodes.session_id') + ->join('oauth_session_redirects', 'oauth_sessions.id', '=', 'oauth_session_redirects.session_id') + ->where('oauth_sessions.client_id', $clientId) + ->where('oauth_session_authcodes.auth_code', $authCode) + ->where('oauth_session_authcodes.auth_code_expires', '>=', time()) + ->where('oauth_session_redirects.redirect_uri', $redirectUri) + ->first(); + + return (is_null($result)) ? false : (array) $result; + } + + /** + * Validate an access token + * @param string $accessToken The access token to be validated + * @return void + */ + public function validateAccessToken($accessToken) + { + $result = DB::table('oauth_session_access_tokens') + ->join('oauth_sessions', 'oauth_session_access_tokens.session_id', '=', 'oauth_sessions.id') + ->where('access_token', $accessToken) + ->where('access_token_expires', '>=', time()) + ->first(); + + return (is_null($result)) ? false : (array) $result; + } + + /** + * Validate a refresh token + * @param string $refreshToken The access token + * @return void + */ + public function validateRefreshToken($refreshToken, $clientId) + { + $result = DB::table('oauth_session_refresh_tokens') + ->where('refresh_token', $refreshToken) + ->where('client_id', $clientId) + ->where('refresh_token_expires', '>=', time()) + ->first(); + + return (is_null($result)) ? false : $result->session_access_token_id; + } + + /** + * Get an access token by ID + * @param int $accessTokenId The access token ID + * @return array + */ + public function getAccessToken($accessTokenId) + { + $result = DB::table('oauth_session_access_tokens') + ->where('id', $accessTokenId) + ->first(); + + return (is_null($result)) ? false : (array) $result; + } + + /** + * Associate a scope with an access token + * @param int $accessTokenId The ID of the access token + * @param int $scopeId The ID of the scope + * @return void + */ + public function associateScope($accessTokenId, $scopeId) + { + DB::table('oauth_session_token_scopes')->insert([ + 'session_access_token_id' => $accessTokenId, + 'scope_id' => $scopeId, + ]); + } + + /** + * Get all associated access tokens for an access token + * @param string $accessToken The access token + * @return array + */ + public function getScopes($accessToken) + { + 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_scopes', 'oauth_session_token_scopes.session_access_token_id', '=', 'oauth_scopes.id') + ->where('access_token', $accessToken) + ->get(); + } +} \ No newline at end of file From 1fcdbf45b2621f63960472ab9de49ff151efb966 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Tue, 14 May 2013 09:45:19 +0100 Subject: [PATCH 02/10] Removed docblocks --- .../OAuth2/Server/Storage/Fluent/Session.php | 81 +------------------ 1 file changed, 1 insertion(+), 80 deletions(-) diff --git a/src/League/OAuth2/Server/Storage/Fluent/Session.php b/src/League/OAuth2/Server/Storage/Fluent/Session.php index 4a235614..7f019bb1 100644 --- a/src/League/OAuth2/Server/Storage/Fluent/Session.php +++ b/src/League/OAuth2/Server/Storage/Fluent/Session.php @@ -4,13 +4,6 @@ use \League\OAuth2\Server\Storage\SessionInterface; class Session implements SessionInterface { - /** - * Create a new session - * @param string $clientId The client ID - * @param string $ownerType The type of the session owner (e.g. "user") - * @param string $ownerId The ID of the session owner (e.g. "123") - * @return int The session ID - */ public function createSession($clientId, $ownerType, $ownerId) { return DB::table('oauth_sessions')->insertGetId([ @@ -20,13 +13,6 @@ class Session implements SessionInterface ]); } - /** - * Delete a session - * @param string $clientId The client ID - * @param string $ownerType The type of the session owner (e.g. "user") - * @param string $ownerId The ID of the session owner (e.g. "123") - * @return void - */ public function deleteSession($clientId, $ownerType, $ownerId) { DB::table('oauth_sessions') @@ -36,12 +22,6 @@ class Session implements SessionInterface ->delete(); } - /** - * Associate a redirect URI with a session - * @param int $sessionId The session ID - * @param string $redirectUri The redirect URI - * @return void - */ public function associateRedirectUri($sessionId, $redirectUri) { DB::table('oauth_session_redirects')->insert([ @@ -50,13 +30,6 @@ class Session implements SessionInterface ]); } - /** - * Associate an access token with a session - * @param int $sessionId The session ID - * @param string $accessToken The access token - * @param int $expireTime Unix timestamp of the access token expiry time - * @return int - */ public function associateAccessToken($sessionId, $accessToken, $expireTime) { return DB::table('oauth_session_access_tokens')->insertGetId([ @@ -66,12 +39,6 @@ class Session implements SessionInterface ]); } - /** - * Associate a refresh token with a session - * @param int $accessTokenId The access token ID - * @param string $refreshToken The refresh token - * @return void - */ public function associateRefreshToken($accessTokenId, $refreshToken, $expireTime, $clientId) { DB::table('oauth_session_refresh_tokens')->insert([ @@ -82,14 +49,6 @@ class Session implements SessionInterface ]); } - /** - * Assocate an authorization code with a session - * @param int $sessionId The session ID - * @param string $authCode The authorization code - * @param int $expireTime Unix timestamp of the access token expiry time - * @param string $scopeIds Comma seperated list of scope IDs to be later associated (default = null) - * @return void - */ public function associateAuthCode($sessionId, $authCode, $expireTime, $scopeIds = null) { DB::table('oauth_session_authcodes')->insert([ @@ -100,11 +59,6 @@ class Session implements SessionInterface ]); } - /** - * Remove an associated authorization token from a session - * @param int $sessionId The session ID - * @return void - */ public function removeAuthCode($sessionId) { DB::table('oauth_session_authcodes') @@ -112,13 +66,6 @@ class Session implements SessionInterface ->delete(); } - /** - * Validate an authorization code - * @param string $clientId The client ID - * @param string $redirectUri The redirect URI - * @param string $authCode The authorization code - * @return void - */ public function validateAuthCode($clientId, $redirectUri, $authCode) { $result = DB::table('oauth_sessions') @@ -134,11 +81,6 @@ class Session implements SessionInterface return (is_null($result)) ? false : (array) $result; } - /** - * Validate an access token - * @param string $accessToken The access token to be validated - * @return void - */ public function validateAccessToken($accessToken) { $result = DB::table('oauth_session_access_tokens') @@ -150,11 +92,6 @@ class Session implements SessionInterface return (is_null($result)) ? false : (array) $result; } - /** - * Validate a refresh token - * @param string $refreshToken The access token - * @return void - */ public function validateRefreshToken($refreshToken, $clientId) { $result = DB::table('oauth_session_refresh_tokens') @@ -166,11 +103,6 @@ class Session implements SessionInterface return (is_null($result)) ? false : $result->session_access_token_id; } - /** - * Get an access token by ID - * @param int $accessTokenId The access token ID - * @return array - */ public function getAccessToken($accessTokenId) { $result = DB::table('oauth_session_access_tokens') @@ -180,13 +112,7 @@ class Session implements SessionInterface return (is_null($result)) ? false : (array) $result; } - /** - * Associate a scope with an access token - * @param int $accessTokenId The ID of the access token - * @param int $scopeId The ID of the scope - * @return void - */ - public function associateScope($accessTokenId, $scopeId) + public function associateScope($accessTokenId, $scopeId) { DB::table('oauth_session_token_scopes')->insert([ 'session_access_token_id' => $accessTokenId, @@ -194,11 +120,6 @@ class Session implements SessionInterface ]); } - /** - * Get all associated access tokens for an access token - * @param string $accessToken The access token - * @return array - */ public function getScopes($accessToken) { return DB::table('oauth_session_token_scopes') From 0b3a9dc88846c28a0223eb91ebdcdd79558b5415 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Tue, 14 May 2013 09:46:14 +0100 Subject: [PATCH 03/10] Converted PHP 5.4 array syntax to old-skool syntax --- .../OAuth2/Server/Storage/Fluent/Session.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/League/OAuth2/Server/Storage/Fluent/Session.php b/src/League/OAuth2/Server/Storage/Fluent/Session.php index 7f019bb1..f23d6ef6 100644 --- a/src/League/OAuth2/Server/Storage/Fluent/Session.php +++ b/src/League/OAuth2/Server/Storage/Fluent/Session.php @@ -6,11 +6,11 @@ class Session implements SessionInterface { public function createSession($clientId, $ownerType, $ownerId) { - return DB::table('oauth_sessions')->insertGetId([ + return DB::table('oauth_sessions')->insertGetId(array( 'client_id' => $clientId, 'owner_type' => $ownerType, 'owner_id' => $ownerId - ]); + )); } public function deleteSession($clientId, $ownerType, $ownerId) @@ -24,39 +24,39 @@ class Session implements SessionInterface public function associateRedirectUri($sessionId, $redirectUri) { - DB::table('oauth_session_redirects')->insert([ + DB::table('oauth_session_redirects')->insert(array( 'session_id' => $sessionId, 'redirect_uri' => $redirectUri, - ]); + )); } 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, 'access_token' => $accessToken, 'access_token_expires' => $expireTime, - ]); + )); } 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, 'refresh_token' => $refreshToken, 'refresh_token_expires' => $expireTime, 'client_id' => $clientId, - ]); + )); } public function associateAuthCode($sessionId, $authCode, $expireTime, $scopeIds = null) { - DB::table('oauth_session_authcodes')->insert([ + DB::table('oauth_session_authcodes')->insert(array( 'session_id' => $sessionId, 'auth_code' => $authCode, 'auth_code_expires' => $expireTime, 'scope_ids' => $scopeIds, - ]); + )); } public function removeAuthCode($sessionId) @@ -114,10 +114,10 @@ class Session implements SessionInterface public function associateScope($accessTokenId, $scopeId) { - DB::table('oauth_session_token_scopes')->insert([ + DB::table('oauth_session_token_scopes')->insert(array( 'session_access_token_id' => $accessTokenId, 'scope_id' => $scopeId, - ]); + )); } public function getScopes($accessToken) From 4d36ebd3e7b9f6eb4775a97224b65c8f45cecb1f Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Tue, 14 May 2013 09:50:40 +0100 Subject: [PATCH 04/10] Added namespaces --- src/League/OAuth2/Server/Storage/Fluent/Client.php | 2 ++ src/League/OAuth2/Server/Storage/Fluent/Scope.php | 2 ++ src/League/OAuth2/Server/Storage/Fluent/Session.php | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/League/OAuth2/Server/Storage/Fluent/Client.php b/src/League/OAuth2/Server/Storage/Fluent/Client.php index 8c8d5a2c..b9e2dab4 100644 --- a/src/League/OAuth2/Server/Storage/Fluent/Client.php +++ b/src/League/OAuth2/Server/Storage/Fluent/Client.php @@ -1,5 +1,7 @@ Date: Sun, 2 Jun 2013 14:40:59 +0100 Subject: [PATCH 05/10] Updated PSR compliance. Added Illuminate\Support\Facades\DB namespace --- src/League/OAuth2/Server/Storage/Fluent/Client.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/League/OAuth2/Server/Storage/Fluent/Client.php b/src/League/OAuth2/Server/Storage/Fluent/Client.php index b9e2dab4..8b24811d 100644 --- a/src/League/OAuth2/Server/Storage/Fluent/Client.php +++ b/src/League/OAuth2/Server/Storage/Fluent/Client.php @@ -2,6 +2,7 @@ namespace League\OAuth2\Server\Storage\Fluent; +use \Illuminate\Support\Facades\DB as DB; use \League\OAuth2\Server\Storage\ClientInterface; class Client implements ClientInterface { @@ -14,16 +15,12 @@ class Client implements ClientInterface { ->where('oauth_clients.id', $clientId) ->where('oauth_client_endpoints.redirect_uri', $redirectUri) ->first(); - } - - elseif ( ! is_null($clientSecret) && is_null($redirectUri)) { + } elseif ( ! is_null($clientSecret) && is_null($redirectUri)) { $result = DB::table('oauth_clients') ->where('id', $clientId) ->where('secret', $clientSecret) ->first(); - } - - elseif ( ! is_null($clientSecret) && ! is_null($redirectUri)) { + } elseif ( ! is_null($clientSecret) && ! is_null($redirectUri)) { $result = DB::table('oauth_clients') ->join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id') ->where('oauth_clients.id', $clientId) From d901e90602f52302f87ef22adddd757a61c6142c Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sun, 2 Jun 2013 14:41:38 +0100 Subject: [PATCH 06/10] Added \Illuminate\Support\Facades\DB namespace --- src/League/OAuth2/Server/Storage/Fluent/Scope.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/League/OAuth2/Server/Storage/Fluent/Scope.php b/src/League/OAuth2/Server/Storage/Fluent/Scope.php index db094243..22a2fe8a 100644 --- a/src/League/OAuth2/Server/Storage/Fluent/Scope.php +++ b/src/League/OAuth2/Server/Storage/Fluent/Scope.php @@ -2,6 +2,7 @@ namespace League\OAuth2\Server\Storage\Fluent; +use \Illuminate\Support\Facades\DB as DB; use \League\OAuth2\Server\Storage\ScopeInterface; class Scope implements ScopeInterface { From 4c4155fdacd770eff42211e254829ddca28eb420 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sun, 2 Jun 2013 14:54:49 +0100 Subject: [PATCH 07/10] Added \Illuminate\Support\Facades\DB namespace --- src/League/OAuth2/Server/Storage/Fluent/Session.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/League/OAuth2/Server/Storage/Fluent/Session.php b/src/League/OAuth2/Server/Storage/Fluent/Session.php index e6f338b0..8af3a39f 100644 --- a/src/League/OAuth2/Server/Storage/Fluent/Session.php +++ b/src/League/OAuth2/Server/Storage/Fluent/Session.php @@ -2,6 +2,7 @@ namespace League\OAuth2\Server\Storage\Fluent; +use \Illuminate\Support\Facades\DB as DB; use \League\OAuth2\Server\Storage\SessionInterface; class Session implements SessionInterface From e442253e26f7e775a40de2c0a4d240692770b9ca Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sun, 2 Jun 2013 14:58:52 +0100 Subject: [PATCH 08/10] Anal spacing fixes and removed PHP5.4+ specific array syntax --- .../OAuth2/Server/Storage/Fluent/Session.php | 81 +++++++++---------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/League/OAuth2/Server/Storage/Fluent/Session.php b/src/League/OAuth2/Server/Storage/Fluent/Session.php index 8af3a39f..dae2464a 100644 --- a/src/League/OAuth2/Server/Storage/Fluent/Session.php +++ b/src/League/OAuth2/Server/Storage/Fluent/Session.php @@ -5,14 +5,14 @@ namespace League\OAuth2\Server\Storage\Fluent; use \Illuminate\Support\Facades\DB as DB; use \League\OAuth2\Server\Storage\SessionInterface; -class Session implements SessionInterface -{ +class Session implements SessionInterface { + public function createSession($clientId, $ownerType, $ownerId) { return DB::table('oauth_sessions')->insertGetId(array( - 'client_id' => $clientId, - 'owner_type' => $ownerType, - 'owner_id' => $ownerId + 'client_id' => $clientId, + 'owner_type' => $ownerType, + 'owner_id' => $ownerId )); } @@ -28,37 +28,36 @@ class Session implements SessionInterface public function associateRedirectUri($sessionId, $redirectUri) { DB::table('oauth_session_redirects')->insert(array( - 'session_id' => $sessionId, - 'redirect_uri' => $redirectUri, + 'session_id' => $sessionId, + 'redirect_uri' => $redirectUri, )); } public function associateAccessToken($sessionId, $accessToken, $expireTime) { return DB::table('oauth_session_access_tokens')->insertGetId(array( - 'session_id' => $sessionId, - 'access_token' => $accessToken, - 'access_token_expires' => $expireTime, + 'session_id' => $sessionId, + 'access_token' => $accessToken, + 'access_token_expires' => $expireTime, )); } public function associateRefreshToken($accessTokenId, $refreshToken, $expireTime, $clientId) { DB::table('oauth_session_refresh_tokens')->insert(array( - 'session_access_token_id' => $accessTokenId, - 'refresh_token' => $refreshToken, - 'refresh_token_expires' => $expireTime, - 'client_id' => $clientId, + 'session_access_token_id' => $accessTokenId, + 'refresh_token' => $refreshToken, + 'refresh_token_expires' => $expireTime, + 'client_id' => $clientId, )); } - public function associateAuthCode($sessionId, $authCode, $expireTime, $scopeIds = null) + public function associateAuthCode($sessionId, $authCode, $expireTime) { DB::table('oauth_session_authcodes')->insert(array( 'session_id' => $sessionId, 'auth_code' => $authCode, - 'auth_code_expires' => $expireTime, - 'scope_ids' => $scopeIds, + 'auth_code_expires' => $expireTime )); } @@ -72,14 +71,14 @@ class Session implements SessionInterface public function validateAuthCode($clientId, $redirectUri, $authCode) { $result = DB::table('oauth_sessions') - ->select('oauth_sessions.id, oauth_session_authcodes.scope_ids') - ->join('oauth_session_authcodes', 'oauth_sessions.id', '=', 'oauth_session_authcodes.session_id') - ->join('oauth_session_redirects', 'oauth_sessions.id', '=', 'oauth_session_redirects.session_id') - ->where('oauth_sessions.client_id', $clientId) - ->where('oauth_session_authcodes.auth_code', $authCode) - ->where('oauth_session_authcodes.auth_code_expires', '>=', time()) - ->where('oauth_session_redirects.redirect_uri', $redirectUri) - ->first(); + ->select(array('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_redirects', 'oauth_sessions.id', '=', 'oauth_session_redirects.session_id') + ->where('oauth_sessions.client_id', $clientId) + ->where('oauth_session_authcodes.auth_code', $authCode) + ->where('oauth_session_authcodes.auth_code_expires', '>=', time()) + ->where('oauth_session_redirects.redirect_uri', $redirectUri) + ->first(); return (is_null($result)) ? false : (array) $result; } @@ -87,10 +86,10 @@ class Session implements SessionInterface public function validateAccessToken($accessToken) { $result = DB::table('oauth_session_access_tokens') - ->join('oauth_sessions', 'oauth_session_access_tokens.session_id', '=', 'oauth_sessions.id') - ->where('access_token', $accessToken) - ->where('access_token_expires', '>=', time()) - ->first(); + ->join('oauth_sessions', 'oauth_session_access_tokens.session_id', '=', 'oauth_sessions.id') + ->where('access_token', $accessToken) + ->where('access_token_expires', '>=', time()) + ->first(); return (is_null($result)) ? false : (array) $result; } @@ -98,10 +97,10 @@ class Session implements SessionInterface public function validateRefreshToken($refreshToken, $clientId) { $result = DB::table('oauth_session_refresh_tokens') - ->where('refresh_token', $refreshToken) - ->where('client_id', $clientId) - ->where('refresh_token_expires', '>=', time()) - ->first(); + ->where('refresh_token', $refreshToken) + ->where('client_id', $clientId) + ->where('refresh_token_expires', '>=', time()) + ->first(); return (is_null($result)) ? false : $result->session_access_token_id; } @@ -109,8 +108,8 @@ class Session implements SessionInterface public function getAccessToken($accessTokenId) { $result = DB::table('oauth_session_access_tokens') - ->where('id', $accessTokenId) - ->first(); + ->where('id', $accessTokenId) + ->first(); return (is_null($result)) ? false : (array) $result; } @@ -118,17 +117,17 @@ class Session implements SessionInterface public function associateScope($accessTokenId, $scopeId) { DB::table('oauth_session_token_scopes')->insert(array( - 'session_access_token_id' => $accessTokenId, - 'scope_id' => $scopeId, + 'session_access_token_id' => $accessTokenId, + 'scope_id' => $scopeId, )); } public function getScopes($accessToken) { 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_scopes', 'oauth_session_token_scopes.session_access_token_id', '=', 'oauth_scopes.id') - ->where('access_token', $accessToken) - ->get(); + ->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') + ->where('access_token', $accessToken) + ->get(); } } \ No newline at end of file From 0999bf4de3813eee699a650921d68e529db6906b Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sun, 2 Jun 2013 14:58:59 +0100 Subject: [PATCH 09/10] Added missing functions --- .../OAuth2/Server/Storage/Fluent/Session.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/League/OAuth2/Server/Storage/Fluent/Session.php b/src/League/OAuth2/Server/Storage/Fluent/Session.php index dae2464a..e188d2ee 100644 --- a/src/League/OAuth2/Server/Storage/Fluent/Session.php +++ b/src/League/OAuth2/Server/Storage/Fluent/Session.php @@ -130,4 +130,27 @@ class Session implements SessionInterface { ->where('access_token', $accessToken) ->get(); } + + public function associateAuthCodeScope($authCodeId, $scopeId) + { + DB::table('oauth_session_authcode_scopes')->insert(array( + 'oauth_session_authcode_id' => $authCodeId, + 'scope_id' => $scopeId + )); + } + + public function getAuthCodeScopes($oauthSessionAuthCodeId) + { + return DB::table('oauth_session_authcode_scopes') + ->where('oauth_session_authcode_id', '=', $oauthSessionAuthCodeId) + ->get(); + } + + public function removeRefreshToken($refreshToken) + { + DB::table('oauth_session_refresh_tokens') + ->where('refresh_token', '=', $refreshToken) + ->delete(); + } + } \ No newline at end of file From f78e05cb0821aa93713d635a722ca583b9e71f17 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sun, 2 Jun 2013 14:59:05 +0100 Subject: [PATCH 10/10] Anal space fixes --- .../OAuth2/Server/Storage/Fluent/Client.php | 24 +++++++++---------- .../OAuth2/Server/Storage/Fluent/Scope.php | 19 +++++++-------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/League/OAuth2/Server/Storage/Fluent/Client.php b/src/League/OAuth2/Server/Storage/Fluent/Client.php index 8b24811d..b8adeb0a 100644 --- a/src/League/OAuth2/Server/Storage/Fluent/Client.php +++ b/src/League/OAuth2/Server/Storage/Fluent/Client.php @@ -11,22 +11,22 @@ class Client implements ClientInterface { { if ( ! is_null($redirectUri) && is_null($clientSecret)) { $result = DB::table('oauth_clients') - ->join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id') - ->where('oauth_clients.id', $clientId) - ->where('oauth_client_endpoints.redirect_uri', $redirectUri) - ->first(); + ->join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id') + ->where('oauth_clients.id', $clientId) + ->where('oauth_client_endpoints.redirect_uri', $redirectUri) + ->first(); } elseif ( ! is_null($clientSecret) && is_null($redirectUri)) { $result = DB::table('oauth_clients') - ->where('id', $clientId) - ->where('secret', $clientSecret) - ->first(); + ->where('id', $clientId) + ->where('secret', $clientSecret) + ->first(); } elseif ( ! is_null($clientSecret) && ! is_null($redirectUri)) { $result = DB::table('oauth_clients') - ->join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id') - ->where('oauth_clients.id', $clientId) - ->where('oauth_clients.secret', $clientSecret) - ->where('oauth_client_endpoints.redirect_uri', $redirectUri) - ->first(); + ->join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id') + ->where('oauth_clients.id', $clientId) + ->where('oauth_clients.secret', $clientSecret) + ->where('oauth_client_endpoints.redirect_uri', $redirectUri) + ->first(); } if (is_null($result)) { diff --git a/src/League/OAuth2/Server/Storage/Fluent/Scope.php b/src/League/OAuth2/Server/Storage/Fluent/Scope.php index 22a2fe8a..a68b7afd 100644 --- a/src/League/OAuth2/Server/Storage/Fluent/Scope.php +++ b/src/League/OAuth2/Server/Storage/Fluent/Scope.php @@ -8,21 +8,20 @@ use \League\OAuth2\Server\Storage\ScopeInterface; class Scope implements ScopeInterface { public function getScope($scope, $clientId = null, $grantType = null) - { - $result = DB::table('oauth_scopes') - ->where('key', $scope) - ->first(); + { + $result = DB::table('oauth_scopes') + ->where('key', $scope) + ->first(); if (is_null($result)) { return false; } return array( - 'id' => $result->id, - 'scope' => $result->key, - 'name' => $result->name, - 'description' => $result->description + 'id' => $result->id, + 'scope' => $result->key, + 'name' => $result->name, + 'description' => $result->description ); - } - + } } \ No newline at end of file