/**
  * Call authorize endpoint
  */
 public function authenticate()
 {
     $this->api = new \OAuth($this->options['consumer_key'], $this->options['consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
     if (!$this->request->query->has('oauth_token') && $this->state === 0) {
         $request_token_info = $this->api->getRequestToken($this->options['request_token_endpoint']);
         $this->secret = $request_token_info['oauth_token_secret'];
         $this->state = 1;
         $this->redirectUrl = $this->request->getPathInfo();
         $this->saveState();
         header(sprintf('Location: %s?oauth_token=%s', $this->options['authorize_endpoint'], $request_token_info['oauth_token']));
     }
 }
예제 #2
0
 function call($command)
 {
     session_start();
     if (!isset($_GET['oauth_token']) && $_SESSION['state'] == 1) {
         $_SESSION['state'] = 0;
     }
     try {
         $oauth = new \OAuth($this->consumer_key, $this->consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
         $oauth->enableDebug();
         if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
             $request_token_info = $oauth->getRequestToken($this->request_url);
             $_SESSION['secret'] = $request_token_info['oauth_token_secret'];
             $_SESSION['state'] = 1;
             header('Location: ' . $this->authorize_url . '?oauth_token=' . $request_token_info['oauth_token']);
             exit;
         } else {
             if ($_SESSION['state'] == 1) {
                 $oauth->setToken($_GET['oauth_token'], $_SESSION['secret']);
                 $access_token_info = $oauth->getAccessToken($this->access_token_url);
                 error_log("acc token info " . $access_token_info, 1, "*****@*****.**");
                 $_SESSION['state'] = 2;
                 $_SESSION['token'] = $access_token_info['oauth_token'];
                 $_SESSION['secret'] = $access_token_info['oauth_token_secret'];
             }
         }
         $oauth->setToken($_SESSION['token'], $_SESSION['secret']);
         $oauth->fetch("{$this->api_url}{$command}");
         $json = json_decode($oauth->getLastResponse());
     } catch (\OAuthException $E) {
         return $E->lastResponse;
     }
     return $json;
 }
예제 #3
0
 function getToken($permissions, $callback_url)
 {
     /* Get a URL to send user to to authenticate for given permissions */
     $oauth = new OAuth($this->site_id, $this->secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
     $token_info = $oauth->getRequestToken(ENTRECARD_API_URL . "/request_token?permissions=" . join(',', $permissions), urlencode($callback_url));
     return array($token_info['oauth_token'], $token_info['oauth_token_secret']);
 }
예제 #4
0
function setOAuth()
{
    //  pecl_oauth
    $oauth = new OAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_FORM);
    $oauth->enableDebug();
    try {
        if (isset($_GET['oauth_token'], $_SESSION['oauth_token_secret'])) {
            $oauth->setToken($_GET['oauth_token'], $_SESSION['oauth_token_secret']);
            $accessToken = $oauth->getAccessToken(TWITTER_ACCESS_URL);
            $_SESSION['oauth_token'] = $accessToken['oauth_token'];
            $_SESSION['oauth_token_secret'] = $accessToken['oauth_token_secret'];
            $response = $oauth->getLastResponse();
            parse_str($response, $get);
            if (!isset($get['user_id'])) {
                throw new Exception('Authentication failed.');
            }
        } else {
            $requestToken = $oauth->getRequestToken(TWITTER_REQUEST_URL);
            $_SESSION['oauth_token_secret'] = $requestToken['oauth_token_secret'];
            header('Location: ' . TWITTER_AUTHORIZE_URL . '?oauth_token=' . $requestToken['oauth_token']);
            die;
        }
    } catch (Exception $e) {
        var_dump($oauth->debugInfo);
        die($e->getMessage());
    }
}
예제 #5
0
파일: Twitter.php 프로젝트: hubgit/libapi
 function authorize()
 {
     $oauth = new OAuth(Config::get('TWITTER_CONSUMER_KEY'), Config::get('TWITTER_CONSUMER_SECRET'), OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
     $oauth->enableDebug();
     try {
         $request_token = $oauth->getRequestToken($this->request_token_url);
     } catch (OAuthException $e) {
         debug($oauth->debugInfo);
     }
     $url = $this->authorize_url . '?' . http_build_query(array('oauth_token' => $request_token['oauth_token'], 'callback_url'));
     print 'Authorize: ' . $url . "\n";
     system(sprintf('open %s', escapeshellarg($url)));
     fwrite(STDOUT, "Enter the PIN: ");
     $verifier = trim(fgets(STDIN));
     //$oauth->setToken($token, $request_token['oauth_token_secret']);
     //$access_token = $oauth->getAccessToken($this->access_token_url);
     $oauth->setToken($request_token['oauth_token'], $request_token['oauth_token_secret']);
     try {
         $access_token = $oauth->getAccessToken($this->access_token_url, NULL, $verifier);
     } catch (OAuthException $e) {
         debug($oauth->debugInfo);
     }
     printf("'TWITTER_TOKEN' => '%s',\n'TWITTER_TOKEN_SECRET' => '%s',\n", $access_token['oauth_token'], $access_token['oauth_token_secret']);
     exit;
 }
예제 #6
0
파일: Twitter.php 프로젝트: joksnet/php-old
 public function getAuthorizationUrl()
 {
     $requestToken = $this->oauth->getRequestToken(self::URL_REQUEST);
     Session::set('Twitter_TokenSecret', $requestToken['oauth_token_secret']);
     # Session::set('Twitter_State', self::STATE_AUTH);
     return self::URL_AUTHORIZE . '?oauth_token=' . $requestToken['oauth_token'];
 }
예제 #7
0
 public function actionLogin($backUrl = '/komunita')
 {
     try {
         $this->getSession('oauth')->back_url = $backUrl;
         $this->getUserDetailsAndLoginUser();
         return;
     } catch (OAuthException $E) {
         // not authentized -> continue below in asking for new token
     }
     // request token
     $request_token_info = $this->oauth->getRequestToken(self::REQUEST_TOKEN_URL);
     //save secret
     $this->getSession('oauth')->login_secret = $request_token_info['oauth_token_secret'];
     //redirect
     $this->redirectUrl(self::AUTHORIZE_URL . "?oauth_token=" . $request_token_info['oauth_token']);
 }
 public static function getAuthURL($consumer_key, $consumer_secret, $callback = null)
 {
     $oauth = new OAuth($consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
     $request_token_info = $oauth->getRequestToken(GOOGLE_OAUTH_REQUEST_TOKEN_API . "?scope=" . SCOPE, $callback);
     $request_token = $request_token_info["oauth_token"];
     $request_secret = $request_token_info["oauth_token_secret"];
     return array("url" => "Location: " . GOOGLE_OAUTH_AUTHORIZE_API . "?oauth_token=" . $request_token . "&scope=" . SCOPE . "&domain=" . $consumer_key, "request_token" => $request_token, "request_secret" => $request_secret);
 }
예제 #9
0
파일: fanfou.php 프로젝트: xuui/iLost
function ilost_get_fanauthorize()
{
    $o = new OAuth(fan_akey, fan_skey);
    $keys = $o->getRequestToken();
    $aurl = $o->getAuthorizeURL($keys['oauth_token'], false, fan_callback);
    $_SESSION['temp'] = $keys;
    return $aurl;
}
예제 #10
0
파일: osmapi.php 프로젝트: tyrasd/Level0
function oauth_login()
{
    global $error;
    try {
        $oauth = new OAuth(CLIENT_ID, CLIENT_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
        $request_token_info = $oauth->getRequestToken(OSM_OAUTH_URL . 'request_token');
        $_SESSION['secret'] = $request_token_info['oauth_token_secret'];
        header('Location: ' . OSM_OAUTH_URL . "authorize?oauth_token=" . $request_token_info['oauth_token']);
        exit;
    } catch (OAuthException $E) {
        $error = 'OAuth error ' . $E->getCode() . ': ' . $E->getMessage();
    }
}
예제 #11
0
 public static function getTemporaryCredentials()
 {
     try {
         $request_token_url = \Fuel\Core\Config::get('evernote.evernote_server') . '/oauth';
         $oauth = new \OAuth(\Fuel\Core\Config::get('evernote.consumer_key'), \Fuel\Core\Config::get('evernote.consumer_secret'));
         $request_token_info = $oauth->getRequestToken($request_token_url, getCallbackUrl());
         if ($request_token_info) {
             \Fuel\Core\Session::set('requestToken', $request_token_info['oauth_token']);
             \Fuel\Core\Session::set('requestTokenSecret', $request_token_info['oauth_token_secret']);
             return TRUE;
         }
     } catch (OAuthException $e) {
     }
     return false;
 }
예제 #12
0
 protected function authorize($sKey, $sSecret)
 {
     if ($this->isAuthorized()) {
         return true;
     }
     try {
         $oConsumer = new OAuth($sKey, $sSecret);
         $oConsumer->setAuthType(OAUTH_AUTH_TYPE_URI);
         $oConsumer->enableDebug();
         $bToken = bx_get('oauth_token') !== false;
         $mixedSecret = $this->oSession->getValue('sys_oauth_secret');
         if (!$bToken && $mixedSecret !== false) {
             $this->oSession->unsetValue('sys_oauth_secret');
             $mixedSecret = false;
         }
         //--- Get request token and redirect to authorize.
         if (!$bToken && $mixedSecret === false) {
             $aRequestToken = $oConsumer->getRequestToken(BX_DOL_OAUTH_URL_REQUEST_TOKEN);
             if (empty($aRequestToken)) {
                 return _t('_adm_err_oauth_cannot_get_token');
             }
             if ($this->isServerError($aRequestToken)) {
                 return $this->processServerError($aRequestToken);
             }
             $this->oSession->setValue('sys_oauth_secret', $aRequestToken['oauth_token_secret']);
             return _t('_adm_msg_oauth_need_authorize', bx_append_url_params(BX_DOL_OAUTH_URL_AUTHORIZE, array('oauth_token' => $aRequestToken['oauth_token'], 'sid' => bx_site_hash())));
         }
         //--- Get access token.
         if ($bToken && $mixedSecret !== false) {
             $oConsumer->setToken(bx_get('oauth_token'), $mixedSecret);
             $aAccessToken = $oConsumer->getAccessToken(bx_append_url_params(BX_DOL_OAUTH_URL_ACCESS_TOKEN, array('oauth_verifier' => bx_get('oauth_verifier'))));
             if (empty($aAccessToken)) {
                 return _t('_adm_err_oauth_cannot_get_token');
             }
             if ($this->isServerError($aAccessToken)) {
                 return $this->processServerError($aAccessToken);
             }
             $this->oSession->setValue('sys_oauth_token', $aAccessToken['oauth_token']);
             $this->oSession->setValue('sys_oauth_secret', $aAccessToken['oauth_token_secret']);
             $this->oSession->setValue('sys_oauth_authorized', 1);
             $this->oSession->setValue('sys_oauth_authorized_user', (int) bx_get('oauth_user'));
             return true;
         }
     } catch (OAuthException $e) {
         return _t('_adm_err_oauth_cannot_get_token');
     }
 }
예제 #13
0
 public static function get_temporary_credentials()
 {
     $consumer_key = Config::get('evernote.oauth_consumer_key');
     $consumer_secret = Config::get('evernote.oauth_consumer_secret');
     $callback_url = Config::get('evernote.callback_url');
     $request_token_url = Config::get('evernote.evernote_server');
     $request_token_url .= Config::get('evernote.request_token_path');
     try {
         $oauth = new OAuth($consumer_key, $consumer_secret);
         $request_token_info = $oauth->getRequestToken($request_token_url, $callback_url);
         if ($request_token_info) {
             return array('oauth_token' => $request_token_info['oauth_token'], 'oauth_token_secret' => $request_token_info['oauth_token_secret']);
         }
     } catch (OAuthException $e) {
         Log::error('Error obtaining temporary credentials: ' . $e->getMessage());
     }
 }
예제 #14
0
 /**
  * @see OAuthHanlder::GetRequestToken()
  */
 public function GetRequestToken($credentials, $scope, $server = NULL, $callbackUrl = NULL, $applicationName = NULL)
 {
     $oauth = new OAuth($credentials['oauth_consumer_key'], $credentials['oauth_consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
     $oauth->setRequestEngine(OAUTH_REQENGINE_CURL);
     $oauth->setVersion('1.0a');
     $params = array('scope' => $scope);
     if (!isset($callbackUrl)) {
         $callbackUrl = parent::$DEFAULT_CALLBACK_URL;
     }
     if (isset($applicationName)) {
         $params['xoauth_displayname'] = $applicationName;
     }
     $endpoint = $this->GetRequestEndpoint($server, $params);
     $response = $oauth->getRequestToken($endpoint, $callbackUrl);
     $credentials['oauth_token'] = $response['oauth_token'];
     $credentials['oauth_token_secret'] = $response['oauth_token_secret'];
     return $credentials;
 }
예제 #15
0
파일: auth.php 프로젝트: ryunhe/everidea
 public function indexAction()
 {
     // $page = new Page('auth');
     // return new Response($page);
     try {
         $oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);
         $requestTokenInfo = $oauth->getRequestToken(REQUEST_TOKEN_URL, $this->getCallbackUrl());
         if ($requestTokenInfo) {
             $_SESSION['requestToken'] = $requestTokenInfo['oauth_token'];
             $_SESSION['requestTokenSecret'] = $requestTokenInfo['oauth_token_secret'];
             return new RedirectResponse($this->getAuthorizationUrl($requestTokenInfo['oauth_token']));
         } else {
             return new FatalErrorResponse('Failed to obtain temporary credentials: ' . $oauth->getLastResponse());
         }
     } catch (OAuthException $e) {
         return new FatalErrorResponse('Error obtaining temporary credentials: ' . $e->getMessage());
     }
 }
예제 #16
0
/**
 * Step 1 and Step 2
 *
 * @param \OAuth $oAuth
 * @param string $requestTokenUrl
 * @param string $authUrl
 *
 * @throws Exception
 */
function oAuthAction($oAuth, $requestTokenUrl, $authUrl)
{
    $callBackUri = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
    $callBackUri .= $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?oauthcallback=1';
    // Step 1 : Obtaining a request token :
    $requestTokenInfo = $oAuth->getRequestToken($requestTokenUrl, $callBackUri, OAUTH_HTTP_METHOD_POST);
    if ($requestTokenInfo['oauth_callback_confirmed'] == 'true') {
        $_SESSION['oauth_token'] = $requestTokenInfo['oauth_token'];
        $_SESSION['oauth_token_secret'] = $requestTokenInfo['oauth_token_secret'];
        session_write_close();
    } else {
        $message = "oauth_callback_confirmed returned from server expected to be 'true', got: ";
        $message .= "'{$requestTokenInfo['oauth_callback_confirmed']}'";
        throw new \Exception($message);
    }
    // Step 2 : Redirecting the user:
    $redirectUri = $authUrl . '?oauth_token=' . $requestTokenInfo['oauth_token'];
    header('Location: ' . $redirectUri);
}
 function signin($type = 'twitter')
 {
     $this->autoRender = false;
     $type_camel = Inflector::camelize($type);
     $api = Configure::read('SocialSignIn.API');
     if (isset($api[$type_camel])) {
         $api = $api[$type_camel];
     } else {
         // $this->redirect($this->referer());
     }
     $config_base = implode('.', array('Auth', $type_camel, ''));
     $consumer_key = Configure::read($config_base . 'consumer_key');
     $consumer_secret = Configure::read($config_base . 'consumer_secret');
     $this->session_basename = Configure::read($config_base . 'session_name');
     // $oauth_callback = $this->redirect_uri;
     $oauth_callback = Router::url(array('plugin' => 'social_sign_in', 'controller' => 'oauth', 'action' => 'callback'), true);
     $oauth = new OAuth($consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
     $request_token_info = $oauth->getRequestToken($api['request_token_url']);
     $this->Session->write($this->session_basename . '.oauth_token', $request_token_info['oauth_token']);
     $this->Session->write($this->session_basename . '.secret', $request_token_info['oauth_token_secret']);
     $url = $api['authorize_url'] . '?oauth_token=' . $request_token_info['oauth_token'];
     $this->redirect($url);
 }
 function __construct()
 {
     // In state=1 the next request should include an oauth_token.
     // If it doesn't go back to 0
     if (!isset($_GET['oauth_token']) && $_SESSION['state'] == 1) {
         $_SESSION['state'] = 0;
     }
     try {
         $oauth = new OAuth(self::CONSKEY, self::CONSSEC, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
         $oauth->enableDebug();
         if ($_SESSION['state'] != 2) {
             if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
                 $queryString = http_build_query(array('scope' => 'https://www.googleapis.com/auth/latitude', 'oauth_callback' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']));
                 $requestToken = $oauth->getRequestToken(self::REQ_URL . '?' . $queryString);
                 $_SESSION['secret'] = $requestToken['oauth_token_secret'];
                 $_SESSION['state'] = 1;
                 $queryString = http_build_query(array('oauth_token' => $requestToken['oauth_token'], 'domain' => $_SERVER['HTTP_HOST'], 'location' => 'all', 'granularity' => 'best'));
                 header('Location: ' . self::AUTH_URL . '?' . $queryString);
                 exit;
             } else {
                 if ($_SESSION['state'] == 1) {
                     $oauth->setToken($_GET['oauth_token'], $_SESSION['secret']);
                     $accessToken = $oauth->getAccessToken(self::ACC_URL);
                     $_SESSION['state'] = 2;
                     $_SESSION['token'] = $accessToken['oauth_token'];
                     $_SESSION['secret'] = $accessToken['oauth_token_secret'];
                 }
             }
         }
         $oauth->setToken($_SESSION['token'], $_SESSION['secret']);
     } catch (OAuthException $e) {
         trigger_error("OAuth fail: " . print_r($e, true));
         print "Oh dear, something failed during the OAuth handshake with google!";
         exit;
     }
     $this->oauth = $oauth;
 }
<?php

require "config.inc.php";
try {
    $o = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
    /* Google scopes are in the following format: urlencoded(scope) urlencoded(scope) */
    $scopes = urlencode("http://www.google.com/calendar/feeds/") . "%20" . urlencode("http://www.blogger.com/feeds/");
    $arrayResp = $o->getRequestToken("https://www.google.com/accounts/OAuthGetRequestToken?scope={$scopes}");
    file_put_contents(OAUTH_TMP_DIR . "/request_token_resp", serialize($arrayResp));
    $authorizeUrl = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token={$arrayResp["oauth_token"]}";
    if (PHP_SAPI == "cli") {
        echo "Navigate your http client to: {$authorizeUrl}\n";
    } else {
        header("Location: {$authorizeUrl}");
    }
} catch (OAuthException $E) {
    echo "Response: " . $E->lastResponse . "\n";
}
예제 #20
0
$client_secret = '';
$app_key = '';
if ($client_key == '' || $client_secret == '' || $app_key == '') {
    exit('You must edit this script to fill in the client_key, client_secret, and app_key');
}
#
# Leg 1 of the three-legged OAuth procedure
#
# This requests temporary credentials from mobage that can be sent
# to the client.
# Use HTTPS!
$server = 'https://app-sandbox.mobage.com';
$url = "{$server}/1/{$app_key}/request_temporary_credential";
$oauth = new OAuth($client_key, $client_secret);
$oauth->enableDebug();
$temporary_credentials = $oauth->getRequestToken($url);
echo '$temporary_credentials: ';
print_r($temporary_credentials);
$oauth->setToken($temporary_credentials['oauth_token'], $temporary_credentials['oauth_token_secret']);
#
# Leg 2
#
# Now you must send the token portion of the temporary credential token to
# the phone and authorize it using:
#  - ngCore/Javascript: Social.Common.Auth.authorizeToken
#  - iOS: [MBAuth authorizeToken:withCallbackQueue:onComplete:]
#  - Android: com.mobage.global.android.social.common.Auth.authorizeToken
# Send the oauth_verifier from the phone back to your app server
echo 'Authorize this token on the device: ' . $temporary_credentials['oauth_token'];
echo "\n - ngCore/Javascript: Social.Common.Auth.authorizeToken";
echo "\n - iOS: [MBAuth authorizeToken:withCallbackQueue:onComplete:]";
예제 #21
0
            $access_token = NULL;
            $access_secret = NULL;
            $access_session = NULL;
            print "Unable to refresh access token, will need to request a new one.\n";
        }
    }
}
// 3. If none of that worked, send the user to get a new token
if (!$access_token) {
    print 'no access token ******************';
    print "Better try to get a new access token.\n";
    $o = new OAuth($consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
    $o->enableDebug();
    $request_token = NULL;
    try {
        $response = $o->getRequestToken("https://api.login.yahoo.com/oauth/v2/get_request_token", 'oob');
        print '<br />';
        print 'response<br /><br />';
        var_dump($response);
        print '<br /><br />';
        print '<br />';
        $request_token = $response['oauth_token'];
        $request_secret = $response['oauth_token_secret'];
        print "Hey! Go to this URL and tell us the verifier you get at the end.\n";
        print ' ' . $response['xoauth_request_auth_url'] . "\n";
    } catch (OAuthException $e) {
        print $e->getMessage() . "\n";
    }
    // Wait for input, then try to use it to get a new access token.
    if ($request_token && $request_secret) {
        print "Type the verifier and hit enter...\n";
예제 #22
0
    /**
     * Create the event RSVP popup
     */
    function meetup_event_popup()
    {
        session_start();
        $header = '<html dir="ltr" lang="en-US">
			<head>
				<meta charset="UTF-8" />
				<meta name="viewport" content="width=device-width" />
				<title>RSVP to a Meetup</title>
				<link rel="stylesheet" type="text/css" media="all" href="' . get_bloginfo('stylesheet_url') . '" />
				<style>
					.button {
						padding:3%;
						color:white;
						background-color:#B03C2D;
						border-radius:3px;
						display:block;
						font-weight:bold;
						width:40%;
						float:left;
						text-align:center;
					}
					.button.no {
						margin-left:8%;
					}
				</style>
			</head>
			<body>
				<div id="page" class="hfeed meetup event" style="padding:15px;">';
        if (array_key_exists('event', $_GET)) {
            $_SESSION['event'] = $_GET['event'];
        }
        if (!array_key_exists('state', $_SESSION)) {
            $_SESSION['state'] = 0;
        }
        // In state=1 the next request should include an oauth_token.
        // If it doesn't go back to 0
        if (!isset($_GET['oauth_token']) && $_SESSION['state'] == 1) {
            $_SESSION['state'] = 0;
        }
        try {
            $oauth = new OAuth($this->key, $this->secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
            $oauth->enableDebug();
            if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
                $request_token_info = $oauth->getRequestToken($this->req_url);
                $_SESSION['secret'] = $request_token_info['oauth_token_secret'];
                $_SESSION['state'] = 1;
                header('Location: ' . $this->authurl . '?oauth_token=' . $request_token_info['oauth_token'] . '&oauth_callback=' . $this->callback_url);
                exit;
            } else {
                if ($_SESSION['state'] == 1) {
                    $oauth->setToken($_GET['oauth_token'], $_SESSION['secret']);
                    $verifier = array_key_exists('verifier', $_GET) ? $_GET['verifier'] : null;
                    $access_token_info = $oauth->getAccessToken($this->acc_url, null, $verifier);
                    $_SESSION['state'] = 2;
                    $_SESSION['token'] = $access_token_info['oauth_token'];
                    $_SESSION['secret'] = $access_token_info['oauth_token_secret'];
                }
            }
            $oauth->setToken($_SESSION['token'], $_SESSION['secret']);
            if (array_key_exists('rsvp', $_GET)) {
                // button has been pressed.
                //send the RSVP.
                if ('yes' == $_GET['rsvp']) {
                    $oauth->fetch("{$this->api_url}/rsvp", array('event_id' => $_SESSION['event'], 'rsvp' => 'yes'), OAUTH_HTTP_METHOD_POST);
                } else {
                    $response = $oauth->fetch("{$this->api_url}/rsvp", array('event_id' => $_SESSION['event'], 'rsvp' => 'no'), OAUTH_HTTP_METHOD_POST);
                }
                $rsvp = json_decode($oauth->getLastResponse());
                echo $header;
                echo '<h1 style="padding:20px 0 0;"><a>' . $rsvp->description . '</a></h1>';
                echo '<p>' . $rsvp->details . '.</p>';
                exit;
            } else {
                // Get event info to display here.
                $oauth->fetch("{$this->api_url}/2/events?event_id=" . $_SESSION['event']);
                $event = json_decode($oauth->getLastResponse());
                $event = $event->results[0];
                $out = '<h1 id="site-title" style="padding:20px 0 0;"><a target="_blank" href="' . $event->event_url . '">' . $event->name . '</a></h1>';
                $out .= '<p style="text-align:justify;">' . $event->description . '</p>';
                $out .= '<p><span class="rsvp-count">' . $event->yes_rsvp_count . ' ' . _n('attendee', 'attendees', $event->yes_rsvp_count) . '</span></p>';
                if (null !== $event->venue) {
                    $venue = $event->venue->name . ' ' . $event->venue->address_1 . ', ' . $event->venue->city . ', ' . $event->venue->state;
                    $out .= "<h3 class='event_location'>Location: <a href='http://maps.google.com/maps?q={$venue}+%28" . $event->venue->name . "%29&z=17' target='_blank'>{$venue}</a></h3>";
                } else {
                    $out .= "<p class='event_location'>Location: TBA</p>";
                }
                $out .= '<h2>' . date('F d, Y @ g:i a', intval($event->time / 1000 + $event->utc_offset / 1000)) . '</h2>';
                echo $header . $out;
                $oauth->fetch("{$this->api_url}/rsvps?event_id=" . $_SESSION['event']);
                $rsvps = json_decode($oauth->getLastResponse());
                $oauth->fetch("{$this->api_url}/members?relation=self");
                $me = json_decode($oauth->getLastResponse());
                $my_id = $me->results[0]->id;
                foreach ($rsvps->results as $user) {
                    if ($my_id == $user->member_id) {
                        echo "<h3 style='padding:20px 0 0; font-weight:normal; font-size:16px'>Your RSVP: <strong>{$user->response}</strong></h3>";
                        echo "<p>You can change your RSVP below.</p>";
                    }
                }
                echo "<h1 style='padding:20px 0 0; font-weight:bold; font-size:22px'>RSVP: </h1>";
                echo "<p style='font-size:.9em'>Please RSVP at meetup.com if you're bringing someone.</p>";
                echo "<a class='button yes' href='{$this->callback_url}&rsvp=yes'>Yes</a>";
                echo "<a class='button no' href='{$this->callback_url}&rsvp=no'>No</a>";
                echo "<p style='clear:both'></p>";
                //echo "<pre>".print_r($event,true)."</pre>";
                exit;
            }
        } catch (OAuthException $E) {
            echo $header;
            echo "<h1 class='entry-title'>There was an error processing your request. Please try again.</h1>";
            if (WP_DEBUG) {
                echo "<pre>" . print_r($E, true) . "</pre>";
            }
        }
        unset($_SESSION['state']);
        unset($_SESSION['event']);
        echo "</div> </body> </html>";
    }
예제 #23
0
     error_log($err . "You must set the OAuth consumer key in the configuration file");
     exit;
 }
 if (!isset($oauth['opera']['consumersecret'])) {
     error_log($err . "You must set the OAuth consumer secret in the configuration file");
     exit;
 }
 $oauthc = new OAuth($oauth['opera']['consumerkey'], $oauth['opera']['consumersecret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
 //initiate
 $oauthc->enableDebug();
 if (empty($_SESSION['orequest_token_secret'])) {
     // first stage is to get and keep the request token and secret
     // and then re-direct the user to page where they enter their
     // credentials for this request, we need to use POST method
     $request_token_url = $oauth['opera']['requesttokenurl'];
     $request_token_info = $oauthc->getRequestToken($request_token_url, OAUTH_HTTP_METHOD_POST);
     // check for errors
     if ($request_token_info == FALSE) {
         error_log($err . "The OAuth server did not provide the request token and secret");
         exit;
     }
     // store the request token & secret for the access token stage
     $_SESSION['orequest_token_secret'] = $request_token_info['oauth_token_secret'];
     $_SESSION['orequest_token'] = $request_token_info['oauth_token'];
     // redirect user to the authorization (login) page
     header("Location: {$oauth['opera']['authurl']}?oauth_token=" . $request_token_info['oauth_token']);
     //forward user to authorize url
 } else {
     if (empty($_SESSION['oaccess_oauth_token'])) {
         // second stage is to request an access token
         // for which we have to provide the verifier
예제 #24
0
    $POD->currentUser()->addMeta('twitter_token', null);
    $POD->currentUser()->addMeta('twitter_id', null);
    $POD->addMessage("Your Twitter account has been removed.");
}
$access_token_info = array();
if (@$_GET['mode'] == 'verify') {
    if ($_SESSION['twitter_state'] == 1 && !isset($_GET['oauth_token'])) {
        $_SESSION['twitter_state'] = 0;
    }
    try {
        $oauth = new OAuth($key, $secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
        $oauth->enableDebug();
        // This will generate debug output in your error_log
        if ($_SESSION['twitter_state'] == 0) {
            // State 0 - Generate request token and redirect user to Twitter to authorize
            $request_token_info = $oauth->getRequestToken('https://twitter.com/oauth/request_token');
            $_SESSION['twitter_token'] = $request_token_info['oauth_token'];
            $_SESSION['twitter_secret'] = $request_token_info['oauth_token_secret'];
            $_SESSION['twitter_state'] = 1;
            header('Location: https://twitter.com/oauth/authorize?oauth_token=' . $_SESSION['twitter_token']);
            exit;
        } else {
            if ($_SESSION['twitter_state'] == 1) {
                // State 1 - Handle callback from Twitter and get and store an access token
                $oauth->setToken($_GET['oauth_token'], $_SESSION['twitter_secret']);
                $access_token_info = $oauth->getAccessToken('https://twitter.com/oauth/access_token');
                $oauth->setToken($access_token_info['oauth_token'], $access_token_info['oauth_token_secret']);
                $oauth->fetch('https://twitter.com/account/verify_credentials.json');
                $json = json_decode($oauth->getLastResponse());
                if ($POD->isAuthenticated()) {
                    $test = $POD->getPeople(array('twitter_token' => $access_token_info['oauth_token']));
예제 #25
0
 The sample also does a log-out at the end to complete the sample.
*/
define('DefaultBrowser', '"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" ');
define('ConsumerKey', 'Your Consumer Key');
define('ConsumerSecret', 'Your Consumer Secret Key');
define('BaseUrl', 'The Oauth server URL');
// https://accounts.autodesk.com/ or https://accounts-staging.autodesk.com/
//- Prepare the PHP OAuth for consuming our Oxygen service
//- Disable the SSL check to avoid an exception with invalidate certificate on the server
$oauth = new OAuth(ConsumerKey, ConsumerSecret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
$oauth->disableSSLChecks();
//- 1st leg: Get the 'request token'
$token = '';
try {
    $token = $oauth->getRequestToken(BaseUrl . "OAuth/RequestToken");
    echo "OAuth/RequestToken response\n", "\toauth_token: {$token['oauth_token']}\n", "\toauth_token_secret: {$token['oauth_token_secret']}\n", "-----------------------\n\n";
    //- Set the token and secret for subsequent requests.
    $oauth->setToken($token['oauth_token'], $token['oauth_token_secret']);
} catch (OAuthException $e) {
    echo "OAuth/RequestToken\n", 'Caught exception: ', $e->getMessage(), "\n";
    exit;
}
//- 2nd leg: Authorize the token
//- Currently, Autodesk Oxygen service requires you to manually log into the system, so we are using your default browser
try {
    $url = BaseUrl . "OAuth/Authorize" . "?oauth_token=" . urlencode(stripslashes($token['oauth_token']));
    exec(DefaultBrowser . $url);
    //- We need to wait for the user to have logged in
    echo "Press [Enter] when logged";
    $psLine = fgets(STDIN, 1024);
예제 #26
0
    /**
     * Create the login popup
     */
    function meetup_login_popup()
    {
        $header = '<html dir="ltr" lang="en-US">
			<head>
				<meta charset="UTF-8" />
				<meta name="viewport" content="width=device-width" />
				<title>RSVP to a Meetup</title>
				<link rel="stylesheet" type="text/css" media="all" href="' . get_bloginfo('stylesheet_url') . '" />
				<style>
					.button {
						padding:3%;
						color:white;
						background-color:#B03C2D;
						border-radius:3px;
						display:block;
						font-weight:bold;
						width:40%;
						float:left;
						text-align:center;
					}
					.button.no {
						margin-left:8%;
					}
				</style>
			</head>
			<body>
				<div id="page" class="hfeed meetup login" style="padding:15px;">';
        if (empty($this->key) || empty($this->secret)) {
            echo $header;
            echo '<p><a href="' . admin_url('options-general.php') . '">Please enter your OAuth key & secret.</a></p>';
            exit;
        }
        session_start();
        if (!array_key_exists('state', $_SESSION)) {
            $_SESSION['state'] = 0;
        }
        if (!isset($_GET['oauth_token']) && $_SESSION['state'] == 1) {
            $_SESSION['state'] = 0;
        }
        try {
            $oauth = new OAuth($this->key, $this->secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
            $oauth->enableDebug();
            if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
                $request_token_info = $oauth->getRequestToken($this->req_url);
                //,plugins_url('vs-oauth.php',__FILE__));
                $_SESSION['secret'] = $request_token_info['oauth_token_secret'];
                $_SESSION['state'] = 1;
                header('Location: ' . $this->authurl . '?oauth_token=' . $request_token_info['oauth_token'] . '&oauth_callback=' . $this->callback_url);
                exit;
            } else {
                if ($_SESSION['state'] == 1) {
                    $oauth->setToken($_GET['oauth_token'], $_SESSION['secret']);
                    $verifier = array_key_exists('verifier', $_GET) ? $_GET['verifier'] : null;
                    $access_token_info = $oauth->getAccessToken($this->acc_url, null, $verifier);
                    $_SESSION['state'] = 2;
                    $_SESSION['token'] = $access_token_info['oauth_token'];
                    $_SESSION['secret'] = $access_token_info['oauth_token_secret'];
                }
            }
            $oauth->setToken($_SESSION['token'], $_SESSION['secret']);
            echo $header;
            $oauth->fetch($this->api_url . "/members?relation=self");
            $response = json_decode($oauth->getLastResponse());
            $meetup = $response->results[0];
            unset($meetup->topics);
            $id = $this->get_user_by_meetup($meetup->id);
            $id = apply_filters('meetup_wp_user_id', $id, $meetup);
            //if the user wasn't found, $id is null, and get_user_by returns false.
            if (false === ($user = get_user_by('id', $id))) {
                //there is no user, so create, and log in.
                $user_info = array('user_login' => sanitize_title($meetup->name), 'user_nicename' => $meetup->name, 'display_name' => $meetup->name, 'nickname' => $meetup->name, 'user_url' => $meetup->link, 'description' => $meetup->bio);
                $new_user = wp_insert_user($user_info);
                if (is_wp_error($new_user)) {
                    wp_die($new_user);
                }
                wp_set_auth_cookie($new_user);
                $user = get_user_by('id', $new_user);
                do_action('meetup_user_create', $user, $meetup);
                $new_user_redirect = apply_filters('meetup_login_new_user_redirect', admin_url('profile.php'), $user);
                echo "<script>window.opener.location.href = '" . $new_user_redirect . "'; window.close();</script>";
            } else {
                wp_set_auth_cookie($user->ID);
                wp_set_current_user($user->ID);
                do_action('meetup_user_update', $user, $meetup);
                $existing_user_redirect = apply_filters('meetup_login_existing_user_redirect', get_bloginfo('url'), $user);
                echo "<script>window.opener.location.href = '" . $existing_user_redirect . "'; window.close();</script>";
            }
        } catch (OAuthException $E) {
            echo $header;
            echo "<h1 class='entry-title'>There was an error processing your request. Please try again.</h1>";
            if (WP_DEBUG) {
                echo "<pre>" . print_r($E, true) . "</pre>";
            }
            if (WP_DEBUG) {
                echo "<pre>" . print_r($_SESSION, true) . "</pre>";
            }
            if (WP_DEBUG) {
                echo "<pre>" . print_r($_GET, true) . "</pre>";
            }
        }
        unset($_SESSION['state']);
    }
예제 #27
0
<?php

include "config/settings.inc.php";
$oauth = new OAuth(PWNED_CONSUMER_KEY, PWNED_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
//initiate
$request_token_info = $oauth->getRequestToken(PWNED_OAUTH_REQUEST_TOKEN);
//get request token
file_put_contents(PWNED_OAUTH_TMP_DIR . "/request_token_resp", serialize($request_token_info));
header('Location: ' . PWNED_OAUTH_AUTHORIZE . '?oauth_token=' . $request_token_info['oauth_token']);
//forward user to authorize url
예제 #28
0
            }
        }
    }
    $scope = json_encode($scope);
    $requestURL .= '?scope=' . urlencode($scope);
}
session_start();
$tokenInfo = null;
try {
    $OAuth = new OAuth($consumerKey, $consumerSecret);
    $OAuth->enableDebug();
    // SSL CA Signed
    if ($self_signed) {
        $OAuth->disableSSLChecks();
    }
    $tokenInfo = $OAuth->getRequestToken($requestURL, $callbackURL);
} catch (Exception $E) {
    echo '<h1>There was an error getting the Request Token</h1>';
    echo '<pre>';
    echo "Message:\n";
    print_r($E->getMessage());
    echo "\n\nLast Response:\n";
    print_r($OAuth->getLastResponse());
    echo "\n\nLast Response Info:\n";
    print_r($OAuth->getLastResponseInfo());
    echo "\n\nDebug Info:\n";
    print_r($OAuth->debugInfo);
    // get info about headers
    echo '</pre>';
}
// Check whether Return is empty or not
예제 #29
0
$temporaryCredentialsRequestUrl = "http://magento-7350-19577-45479.cloudwaysapps.com/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://magento-7350-19577-45479.cloudwaysapps.com/admin/oAuth_authorize';
$accessTokenRequestUrl = 'http://magento-7350-19577-45479.cloudwaysapps.com/oauth/token';
$apiUrl = 'http://magento-7350-19577-45479.cloudwaysapps.com/api/rest';
$consumerKey = 'eedcf9497ab5d8ac3d0bb36a9a5ec2ff';
$consumerSecret = '5dfa269c5eea1403a309aac0980b7565';
session_start();
if (!isset($_GET['oauth_token']) && isset($_SESSION['state']) && $_SESSION['state'] == 1) {
    $_SESSION['state'] = 0;
}
try {
    $authType = $_SESSION['state'] == 2 ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
    $oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
    $oauthClient->enableDebug();
    if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
        $requestToken = $oauthClient->getRequestToken($temporaryCredentialsRequestUrl);
        $_SESSION['secret'] = $requestToken['oauth_token_secret'];
        $_SESSION['state'] = 1;
        header('Location: ' . $adminAuthorizationUrl . '?oauth_token=' . $requestToken['oauth_token']);
        exit;
    } else {
        if ($_SESSION['state'] == 1) {
            $oauthClient->setToken($_GET['oauth_token'], $_SESSION['secret']);
            $accessToken = $oauthClient->getAccessToken($accessTokenRequestUrl);
            $_SESSION['state'] = 2;
            $_SESSION['token'] = $accessToken['oauth_token'];
            $_SESSION['secret'] = $accessToken['oauth_token_secret'];
            header('Location: ' . $callbackUrl);
            exit;
        } else {
            $oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);
#!/usr/bin/env php
<?php 
require "config.inc.php";
try {
    $oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
    /* Google scopes are in the following format: urlencoded(scope) urlencoded(scope) */
    $scopes = urlencode("http://www.google.com/calendar/feeds/") . "%20" . urlencode("http://www.blogger.com/feeds/") . "%20" . urlencode("http://www-opensocial.googleusercontent.com/api/people/");
    $request_token_info = $oauth->getRequestToken(GOOGLE_OAUTH_REQUEST_TOKEN_API . "?scope={$scopes}");
    printf("Request token: %s\n", $request_token_info["oauth_token"]);
    printf("Request token secret: %s\n\n", $request_token_info["oauth_token_secret"]);
    printf("I think I got a valid request token, navigate your www client to:\n\n%s?oauth_token=%s\n\nOnce you finish authorizing, hit ENTER or INTERRUPT to exit\n", GOOGLE_OAUTH_AUTHORIZE_API, $request_token_info["oauth_token"]);
    $in = fopen("php://stdin", "r");
    fgets($in, 255);
    $oauth->setToken($request_token_info["oauth_token"], $request_token_info["oauth_token_secret"]);
    /* grab the access token, which is your persistent token which you use for future requests */
    printf("Grabbing an access token...\n");
    $access_token_info = $oauth->getAccessToken(GOOGLE_OAUTH_ACCESS_TOKEN_API);
    printf("Access token: %s\n", $access_token_info["oauth_token"]);
    printf("Access token secret: %s\n\n", $access_token_info["oauth_token_secret"]);
    printf("Fetching contacts in JSON via %s\n", GOOGLE_POCO_CONTACT_INFO_API);
    $oauth->setToken($access_token_info["oauth_token"], $access_token_info["oauth_token_secret"]);
    /* put the OAuth params into the Authorization header */
    $oauth->setAuthType(OAUTH_AUTH_TYPE_AUTHORIZATION);
    $oauth->fetch(GOOGLE_POCO_CONTACT_INFO_API);
    /* from this point on OAuth is over, now handling the JSON response is in order */
    $json = json_decode($oauth->getLastResponse());
    printf("My contact information at Google: \nGiven name: %s\nFamily name: %s\nDisplay name: %s\n\n", $json->entry->name->givenName, $json->entry->name->familyName, $json->entry->displayName);
    printf("Fetching all of {$json->entry->displayName}'s contacts in JSON via %s\n", GOOGLE_POCO_ALL_CONTACTS);
    $oauth->fetch(GOOGLE_POCO_ALL_CONTACTS);
    $json = json_decode($oauth->getLastResponse());
    printf("=== Total contacts: %d, showing: %d-%d ===\n", $json->totalResults, $json->startIndex + 1, sizeof($json->entry));