Exemple #1
0
 public function post($url, $params = null)
 {
     $req = new WebRequest($this->preparedUrl($url));
     $result = $req->post($params);
     $this->_lastStatusCode = $req->getLastStatus();
     return $this->validateRequest($result);
 }
Exemple #2
0
 /**
  * Handle OAuth 2.0 Flow
  * @return BaseOAuth20
  */
 public function handle()
 {
     // Get Var Elements
     $accessToken = $this->getAccessToken();
     $state = $this->getVar("state");
     // Initiate OAuth Client with Specific server configuration
     $to = new $this->_className();
     // Try to Handle the Authentication Process
     if ($accessToken == "") {
         $code = $this->_context->get("code");
         // If not received the "Code" Parameter, initiate the autorization request
         if ($code == "") {
             $state = md5(uniqid(rand(), TRUE));
             //CSRF protection
             $this->setVar("state", $state);
             $params = array("client_id" => $this->_client_id, "redirect_uri" => $this->_redirect_uri, "state" => $state, "scope" => $this->_scope);
             if (count($this->_extraArgs) > 0) {
                 $params = array_merge($params, $this->_extraArgs);
             }
             $req = new WebRequest($to->authorizationURL());
             $req->redirect($params, $this->_window_top);
         }
         // Request the Access Token
         if ($this->_context->get("state") == $this->getVar("state")) {
             $params = array("client_id" => $this->_client_id, "redirect_uri" => $this->_redirect_uri, "client_secret" => $this->_client_secret, "code" => $code, "grant_type" => "authorization_code");
             $req = new WebRequest($to->accessTokenURL());
             $result = $req->post($params);
             $accessToken = $to->decodeAccessToken($result);
             $this->setVar("access_token", $accessToken);
             $to->setAccessToken($accessToken);
             $this->saveAccessToken();
             if ($this->_app_uri != "") {
                 $req = new WebRequest($this->_app_uri);
                 $response = $req->redirect();
             }
         }
     } else {
         $to->setAccessToken($this->getVar('access_token'));
     }
     return $to;
 }