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..b8adeb0a --- /dev/null +++ b/src/League/OAuth2/Server/Storage/Fluent/Client.php @@ -0,0 +1,44 @@ +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..a68b7afd --- /dev/null +++ b/src/League/OAuth2/Server/Storage/Fluent/Scope.php @@ -0,0 +1,27 @@ +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..e188d2ee --- /dev/null +++ b/src/League/OAuth2/Server/Storage/Fluent/Session.php @@ -0,0 +1,156 @@ +insertGetId(array( + 'client_id' => $clientId, + 'owner_type' => $ownerType, + 'owner_id' => $ownerId + )); + } + + public function deleteSession($clientId, $ownerType, $ownerId) + { + DB::table('oauth_sessions') + ->where('client_id', $clientId) + ->where('owner_type', $ownerType) + ->where('owner_id', $ownerId) + ->delete(); + } + + public function associateRedirectUri($sessionId, $redirectUri) + { + 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(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(array( + 'session_access_token_id' => $accessTokenId, + 'refresh_token' => $refreshToken, + 'refresh_token_expires' => $expireTime, + 'client_id' => $clientId, + )); + } + + public function associateAuthCode($sessionId, $authCode, $expireTime) + { + DB::table('oauth_session_authcodes')->insert(array( + 'session_id' => $sessionId, + 'auth_code' => $authCode, + 'auth_code_expires' => $expireTime + )); + } + + public function removeAuthCode($sessionId) + { + DB::table('oauth_session_authcodes') + ->where('session_id', $sessionId) + ->delete(); + } + + public function validateAuthCode($clientId, $redirectUri, $authCode) + { + $result = DB::table('oauth_sessions') + ->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; + } + + 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; + } + + 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; + } + + public function getAccessToken($accessTokenId) + { + $result = DB::table('oauth_session_access_tokens') + ->where('id', $accessTokenId) + ->first(); + + return (is_null($result)) ? false : (array) $result; + } + + public function associateScope($accessTokenId, $scopeId) + { + DB::table('oauth_session_token_scopes')->insert(array( + '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(); + } + + 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