public function action_do() { $params = Oauth2::parse_query(); try { if (empty($params['code']) or isset($params['error'])) { throw new Oauth2_Exception($params['error']); } $token = Remote::get($this->_configs['token_uri'], array(CURLOPT_POST => TRUE, CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form-urlencoded;charset=utf-8'), CURLOPT_POSTFIELDS => Oauth2::build_query(array('grant_type' => $this->_configs['grant_type'], 'code' => $params['code'], 'client_id' => $this->_configs['client_id'], 'redirect_uri' => $this->_configs['redirect_uri'], 'client_secret' => $this->_configs['client_secret'])))); $token = json_decode($token); if (isset($token->error)) { throw new Oauth2_Exception($token->error); } // Resource in json format $resource = Remote::get($this->_configs['access_uri'], array(CURLOPT_POST => TRUE, CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form-urlencoded;charset=utf-8'), CURLOPT_POSTFIELDS => Oauth2::build_query(array('oauth_token' => $token->access_token, 'timestamp' => $_SERVER['REQUEST_TIME'], 'refresh_token' => $token->refresh_token, 'expires_in' => $token->expires_in, 'client_id' => $this->_configs['client_id'])))); $this->request->response = $resource; } catch (Exception $e) { $error = $e->getMessage(); } if (isset($error)) { switch ($error) { case 'access_denied': $this->request->response = 'You have denied this request.'; break; default: $this->request->response = 'There must be some errors happen in this connection, please contact our web master.' . "[{$error}]"; break; } } }
public function query() { if (empty($this->error)) { $form = get_object_vars($this); foreach ($form as $key => $val) { if (empty($val)) { unset($form[$key]); } } } else { $form = array('error' => $this->error); if (property_exists($this, 'error_description') and $this->error_description) { $form['error_description'] = $this->error_description; } if (property_exists($this, 'error_uri') and $this->error_uri) { $form['error_uri'] = $this->error_uri; } if (property_exists($this, 'state') and $this->state) { $form['state'] = $this->state; } } return Oauth2::build_query($form); }
/** * Normalized request string for signature verify * * @access public * @param string $method * @param string $uri * @param array $params * @return string */ public static function normalize($method, $uri, array $params) { // ~ The oauth_signature parameter MUST be excluded. unset($params['signature']); return $method . '&' . Oauth::urlencode($uri) . '&' . Oauth2::build_query($params); }