function api_content(&$a) { if (App::$cmd == 'api/oauth/authorize') { /* * api/oauth/authorize interact with the user. return a standard page */ App::$page['template'] = "minimal"; // get consumer/client from request token try { $request = OAuth1Request::from_request(); } catch (Exception $e) { echo "<pre>"; var_dump($e); killme(); } if (x($_POST, 'oauth_yes')) { $app = oauth_get_client($request); if (is_null($app)) { return "Invalid request. Unknown token."; } $consumer = new OAuth1Consumer($app['client_id'], $app['pw'], $app['redirect_uri']); $verifier = md5($app['secret'] . local_channel()); set_config("oauth", $verifier, local_channel()); if ($consumer->callback_url != null) { $params = $request->get_parameters(); $glue = "?"; if (strstr($consumer->callback_url, $glue)) { $glue = "?"; } goaway($consumer->callback_url . $glue . "oauth_token=" . OAuth1Util::urlencode_rfc3986($params['oauth_token']) . "&oauth_verifier=" . OAuth1Util::urlencode_rfc3986($verifier)); killme(); } $tpl = get_markup_template("oauth_authorize_done.tpl"); $o = replace_macros($tpl, array('$title' => t('Authorize application connection'), '$info' => t('Return to your app and insert this Securty Code:'), '$code' => $verifier)); return $o; } if (!local_channel()) { //TODO: we need login form to redirect to this page notice(t('Please login to continue.') . EOL); return login(false, 'api-login', $request->get_parameters()); } //FKOAuth1::loginUser(4); $app = oauth_get_client($request); if (is_null($app)) { return "Invalid request. Unknown token."; } $tpl = get_markup_template('oauth_authorize.tpl'); $o = replace_macros($tpl, array('$title' => t('Authorize application connection'), '$app' => $app, '$authorize' => t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'), '$yes' => t('Yes'), '$no' => t('No'))); //echo "<pre>"; var_dump($app); killme(); return $o; } echo api_call($a); killme(); }
function api_oauth_access_token($a, $type) { try { $oauth = new ZotOAuth1(); $req = OAuth1Request::from_request(); $r = $oauth->fetch_access_token($req); } catch (Exception $e) { echo "error=" . OAuth1Util::urlencode_rfc3986($e->getMessage()); killme(); } echo $r; killme(); }
/** * One time exchange of username and password for access token and secret. * * @returns array("oauth_token" => "the-access-token", * "oauth_token_secret" => "the-access-secret", * "user_id" => "9436992", * "screen_name" => "abraham", * "x_auth_expires" => "0") */ function getXAuthToken($username, $password) { $parameters = array(); $parameters['x_auth_username'] = $username; $parameters['x_auth_password'] = $password; $parameters['x_auth_mode'] = 'client_auth'; $request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters); $token = OAuth1Util::parse_parameters($request); $this->token = new OAuth1Consumer($token['oauth_token'], $token['oauth_token_secret']); return $token; }
public static function build_http_query($params) { if (!$params) { return ''; } // Urlencode both keys and values $keys = OAuth1Util::urlencode_rfc3986(array_keys($params)); $values = OAuth1Util::urlencode_rfc3986(array_values($params)); $params = array_combine($keys, $values); // Parameters are sorted by name, using lexicographical byte value ordering. // Ref: Spec: 9.1.1 (1) uksort($params, 'strcmp'); $pairs = array(); foreach ($params as $parameter => $value) { if (is_array($value)) { // If two or more parameters share the same name, they are sorted by their value // Ref: Spec: 9.1.1 (1) natsort($value); foreach ($value as $duplicate_value) { $pairs[] = $parameter . '=' . $duplicate_value; } } else { $pairs[] = $parameter . '=' . $value; } } // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61) // Each name-value pair is separated by an '&' character (ASCII code 38) return implode('&', $pairs); }