コード例 #1
0
 /**
  * Handle request token, access token and xAuth login
  */
 protected function handle($action)
 {
     $response = [];
     //\Debugbar::disable();
     $now = new Carbon();
     try {
         $statusCode = 200;
         $response = ['result' => ['status' => 'success', 'code' => $statusCode, 'server' => $_SERVER['SERVER_ADDR'], 'time' => $now->timestamp, 'version' => 1]];
         switch ($action) {
             case 'requestToken':
                 $result = OAuthServer::requestToken();
                 break;
             case 'accessToken':
                 $result = OAuthServer::accessToken();
                 break;
             case 'xAuth':
                 $result = OAuthServer::xAuth();
                 break;
             case 'logout':
                 $result = OAuthServer::logout();
                 break;
             default:
                 throw OAuthException::make(OAuthException::SERVICE_UNAVAILABLE);
         }
         $response = array_merge($response, $result);
     } catch (OAuthException $e) {
         $statusCode = 400;
         $response = ['result' => ['status' => 'error', 'code' => $statusCode, 'message' => $e->getName(), 'server' => $_SERVER['SERVER_ADDR'], 'time' => $now->timestamp, 'version' => 1, 'errors' => [['message' => $e->getMessage(), 'code' => $e->getCode(), 'method' => \Request::method(), 'url' => \Request::fullUrl()]]]];
     } catch (\Exception $e) {
         \Log::error($e, ['method' => \Request::method(), 'url' => \Request::fullUrl(), 'error' => 'OAuth exception occured']);
         $statusCode = 500;
         $response = ['status' => 'error', 'code' => $statusCode, 'server' => $_SERVER['SERVER_ADDR'], 'time' => $now->timestamp, 'version' => 1, 'errors' => [['message' => 'Error occured', 'code' => 500, 'method' => \Request::method(), 'url' => \Request::fullUrl()]]];
     } finally {
         return \Response::json($response, $statusCode);
     }
 }
コード例 #2
0
 /**
  * Verify the authorization information
  *
  * @return array The state of authorization flow
  */
 public function authorizeVerify()
 {
     // Authorization implementation goes here
     $token = $this->getParam(self::OAUTH_TOKEN, true);
     if (!isset($this->storages['request_token'])) {
         throw new \RuntimeException('You must supply a storage object implementing ' . $this->storageMap['request_token']);
     }
     $requestToken = $this->storages['request_token']->getRequestToken($token);
     if (!$requestToken) {
         throw OAuthException::make(OAuthException::TOKEN_REJECTED, ['value' => $token]);
     }
     $state = $this->loadState();
     // We need to remember the callback
     if (empty($state['token']) || strcmp($state['token'], $requestToken['token'])) {
         $state['token'] = $requestToken['token'];
         $state['consumer_key'] = $requestToken['consumer_key'];
         $cb = $this->getParam(self::OAUTH_CALLBACK, true);
         if ($cb) {
             $state['callback_url'] = $cb;
         } else {
             $state['callback_url'] = $requestToken['callback_url'];
         }
         $this->storeState($state);
     }
     return $state;
 }
コード例 #3
0
 /**
  * Perform version check.
  * @exception OAuthException thrown when sanity checks failed
  */
 protected function verifyVersion()
 {
     $version = $this->getParam(self::OAUTH_VERSION, true);
     if (empty($version)) {
         throw OAuthException::make(OAuthException::PARAMETER_ABSENT, ['name' => self::OAUTH_VERSION]);
     }
     if ($version != '1.0' && $version != '1.0a') {
         throw OAuthException::make(OAuthException::VERSION_REJECTED, ['value' => $version]);
     }
 }