Ejemplo n.º 1
0
 function createAuthHeader($url = null, $request_type = null)
 {
     if ($this->auth_type == 'client') {
         return "Authorization: GoogleLogin auth=" . $this->auth;
     } else {
         if ($url == NULL) {
             error_log('No URL to sign.');
         }
         $signature_method = new GADOAuthSignatureMethod_HMAC_SHA1();
         $params = array();
         $consumer = new GADOAuthConsumer('anonymous', 'anonymous', NULL);
         $token = new GADOAuthConsumer($this->oauth_token, $this->oauth_secret);
         $oauth_req = GADOAuthRequest::from_consumer_and_token($consumer, $token, $request_type, $url, $params);
         $oauth_req->sign_request($signature_method, $consumer, $token);
         return $oauth_req->to_header();
     }
 }
Ejemplo n.º 2
0
 /**
  * pretty much a helper function to set up the request
  */
 public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters = NULL)
 {
     $parameters = $parameters ? $parameters : array();
     $defaults = array("oauth_version" => GADOAuthRequest::$version, "oauth_nonce" => GADOAuthRequest::generate_nonce(), "oauth_timestamp" => GADOAuthRequest::generate_timestamp(), "oauth_consumer_key" => $consumer->key);
     if ($token) {
         $defaults['oauth_token'] = $token->key;
     }
     $parameters = array_merge($defaults, $parameters);
     return new GADOAuthRequest($http_method, $http_url, $parameters);
 }
Ejemplo n.º 3
0
 function admin_handle_oauth_complete()
 {
     // step two in oauth login process
     if (function_exists('current_user_can') && !current_user_can('manage_options')) {
         die(__('Cheatin’ uh?'));
     }
     $signature_method = new GADOAuthSignatureMethod_HMAC_SHA1();
     $params = array();
     $params['oauth_verifier'] = $_REQUEST['oauth_verifier'];
     $consumer = new GADOAuthConsumer('anonymous', 'anonymous', NULL);
     $upgrade_token = new GADOAuthConsumer(get_option('gad_oa_anon_token'), get_option('gad_oa_anon_secret'));
     $acc_req = GADOAuthRequest::from_consumer_and_token($consumer, $upgrade_token, 'GET', 'https://www.google.com/accounts/OAuthGetAccessToken', $params);
     $acc_req->sign_request($signature_method, $consumer, $upgrade_token);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $acc_req->to_url());
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $oa_response = curl_exec($ch);
     if (curl_errno($ch)) {
         $error_message = curl_error($ch);
         $info_redirect = gad_get_admin_url('/options-general.php') . '?page=google-analytics-dashboard/gad-admin-options.php&error_message=' . urlencode($error_message);
         header("Location: " . $info_redirect);
         die("");
     }
     $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     delete_option('gad_oa_anon_token');
     delete_option('gad_oa_anon_secret');
     if ($http_code == 200) {
         $access_params = $this->split_params($oa_response);
         update_option('gad_oauth_token', $access_params['oauth_token']);
         update_option('gad_oauth_secret', $access_params['oauth_token_secret']);
         update_option('gad_auth_token', 'gad_see_oauth');
         $info_redirect = gad_get_admin_url('/options-general.php') . '?page=google-analytics-dashboard/gad-admin-options.php&info_message=' . urlencode('Authenticated!');
         header("Location: " . $info_redirect);
     } else {
         $info_redirect = gad_get_admin_url('/options-general.php') . '?page=google-analytics-dashboard/gad-admin-options.php&error_message=' . urlencode($oa_response);
         header("Location: " . $info_redirect);
     }
     die("");
 }