Beispiel #1
0
/**
 * Upgrades an OAuth request token to an access token.
 *
 * @param string $request_token_str An authorized OAuth request token
 * @return string The access token
 */
function getAccessToken($request_token_str)
{
    global $consumer, $SIG_METHOD, $OAUTH_ENDPOINT;
    $token = new OAuthToken($request_token_str, NULL);
    $token_endpoint = "{$OAUTH_ENDPOINT}/oauth/access_token";
    $request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $token_endpoint);
    $request->sign_request($SIG_METHOD, $consumer, $token);
    $response = send_signed_request($request->get_normalized_http_method(), $token_endpoint, $request->to_header(), NULL, false);
    // Parse out oauth_token (access token) and oauth_token_secret
    $matches = array();
    @parse_str($response, $matches);
    $access_token = new OAuthToken(urldecode($matches['oauth_token']), urldecode($matches['oauth_token_secret']));
    return $access_token;
}
Beispiel #2
0
            $params = array('scope' => $scope, 'oauth_callback' => $callback);
            $request = OAuthRequest::from_consumer_and_token($consumer, null, 'GET', $url, $params);
            $request->sign_request($sigMethod, $consumer, null);
            $response = send_signed_request('GET', $url, array($request->to_header()), null, false);
            $token = array();
            parse_str($response, $token);
            if (isset($token['oauth_token']) && isset($token['oauth_token_secret'])) {
                $authUrl = 'https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=' . $token['oauth_token'];
                OCP\JSON::success(array('data' => array('url' => $authUrl, 'request_token' => $token['oauth_token'], 'request_token_secret' => $token['oauth_token_secret'])));
            } else {
                OCP\JSON::error(array('data' => array('message' => 'Fetching request tokens failed. Error: ' . $response)));
            }
            break;
        case 2:
            if (isset($_POST['oauth_verifier']) && isset($_POST['request_token']) && isset($_POST['request_token_secret'])) {
                $token = new OAuthToken($_POST['request_token'], $_POST['request_token_secret']);
                $url = 'https://www.google.com/accounts/OAuthGetAccessToken';
                $request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $url, array('oauth_verifier' => $_POST['oauth_verifier']));
                $request->sign_request($sigMethod, $consumer, $token);
                $response = send_signed_request('GET', $url, array($request->to_header()), null, false);
                $token = array();
                parse_str($response, $token);
                if (isset($token['oauth_token']) && isset($token['oauth_token_secret'])) {
                    OCP\JSON::success(array('access_token' => $token['oauth_token'], 'access_token_secret' => $token['oauth_token_secret']));
                } else {
                    OCP\JSON::error(array('data' => array('message' => 'Fetching access tokens failed. Error: ' . $response)));
                }
            }
            break;
    }
}
Beispiel #3
0
        if (!$result) {
            die("{'html_link' : '" . $req->to_url() . "', " . "'base_string' : '" . $req->get_signature_base_string() . "', " . "'response' : '" . $result . "'}");
            // return json
        }
        $result = split('<', $result, 2);
        // If response was not XML xml_pretty_printer() will throw exception.
        // In that case, set the response body directly from the result
        try {
            $response_body = @xml_pretty_printer(isset($result[1]) ? '<' . $result[1] : $result[0], true);
        } catch (Exception $e) {
            $response_body = isset($result[1]) ? '<' . $result[1] : $result[0];
        }
        // <pre> tags needed for IE
        $response_body = '<pre>' . $response_body . '</pre>';
        echo json_encode(array('html_link' => $req->to_url(), 'base_string' => $req->get_signature_base_string(), 'headers' => isset($result[1]) ? $result[0] : '', 'response' => $response_body, 'authorization_header' => $auth_header));
        exit;
        break;
        // 'available feeds' button. Uses AuthSubTokenInfo to parse out feeds the token can access.
    // 'available feeds' button. Uses AuthSubTokenInfo to parse out feeds the token can access.
    case 'discovery':
        $url = 'https://www.google.com/accounts/AuthSubTokenInfo';
        $req = OAuthRequest::from_consumer_and_token($consumer, $oauth_token, 'GET', $url);
        $req->sign_request($sig_method, $consumer, $oauth_token, $privKey);
        $response = send_signed_request('GET', $req);
        // Parse out valid scopes returned for this access token
        preg_match_all('/Scope.*=(.*)/', $response, $matches);
        echo json_encode(array('html_link' => $req->to_url(), 'base_string' => $req->get_signature_base_string(), 'authorization_header' => $req->to_header(), 'args' => json_encode($matches[1]), 'callback' => 'getAvailableFeeds'));
        exit;
        // ajax request, just stop execution
        break;
}
Beispiel #4
0
/**
 * Upgrades an OAuth request token to an access token.
 *
 * @param string $request_token_str An authorized OAuth request token
 * @return string The access token
 */
function getAccessToken($request_token_str)
{
    global $consumer, $sig_method;
    $token = new OAuthToken($request_token_str, NULL);
    $token_endpoint = 'https://www.google.com/accounts/OAuthGetAccessToken';
    $request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $token_endpoint);
    $request->sign_request($sig_method, $consumer, $token);
    $response = send_signed_request($request->get_normalized_http_method(), $token_endpoint, $request->to_header(), NULL, false);
    // Parse out oauth_token (access token) and oauth_token_secret
    preg_match('/oauth_token=(.*)&oauth_token_secret=(.*)/', $response, $matches);
    $access_token = new OAuthToken(urldecode($matches[1]), urldecode($matches[2]));
    return $access_token;
}
Beispiel #5
0
 $s1 = $Setting->find_by(array('name' => $optfind));
 $scope = 'https://mail.google.com/mail/feed/atom/';
 $base_url = $request->base;
 $endpoint = $scope;
 $parsed = parse_url($endpoint);
 $params = array();
 parse_str($parsed['query'], $params);
 lib_include('twitteroauth');
 $key = environment('googleKey');
 $secret = environment('googleSecret');
 $consumer = new OAuthConsumer($key, $secret, NULL);
 $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
 $token = get_oauth_token(get_option('google_key', $s1->profile_id), get_option('google_secret', $s1->profile_id));
 $oauth_req = OAuthRequest::from_consumer_and_token($consumer, $token, "GET", $endpoint, $params);
 $oauth_req->sign_request($hmac_method, $consumer, $token);
 $responseString = send_signed_request($oauth_req->get_normalized_http_method(), $endpoint, $oauth_req->to_header(), NULL, false);
 $data = $responseString;
 $xml = new SimpleXmlElement($data);
 foreach ($xml as $k1 => $v1) {
     $values = array();
     foreach ($v1 as $k2 => $v2) {
         if ($k2 == 'title') {
             $values['title'] = (string) $v2;
         } elseif ($k2 == 'link') {
             $values['url'] = (string) $v2['href'];
             $parsed = parse_url($values['url']);
             $params = array();
             parse_str($parsed['query'], $params);
             $values['acct'] = $params['account_id'];
         } elseif ($k2 == 'author') {
             foreach ($v2 as $k => $v) {