123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class ApiOAuthRequestTokenAction extends ApiOAuthAction
- {
-
- function prepare(array $args = array())
- {
- parent::prepare($args);
-
-
- return true;
- }
-
- function handle()
- {
- parent::handle();
- $datastore = new ApiGNUsocialOAuthDataStore();
- $server = new OAuthServer($datastore);
- $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
- $server->add_signature_method($hmac_method);
- try {
- $req = OAuthRequest::from_request();
-
- if (!$this->verifyCallback($req->get_parameter('oauth_callback'))) {
- throw new OAuthException(
- "You must provide a valid URL or 'oob' in oauth_callback.",
- 400
- );
- }
-
- $token = $server->fetch_request_token($req);
- common_log(
- LOG_INFO,
- sprintf(
- "API OAuth - Issued request token %s for consumer %s with oauth_callback %s",
- $token->key,
- $req->get_parameter('oauth_consumer_key'),
- "'" . $req->get_parameter('oauth_callback') ."'"
- )
- );
-
- $this->showRequestToken($token);
- } catch (OAuthException $e) {
- common_log(LOG_WARNING, 'API OAuthException - ' . $e->getMessage());
-
-
- $code = $e->getCode();
- $this->clientError($e->getMessage(), empty($code) ? 401 : $code, 'text');
- }
- }
-
- function showRequestToken($token)
- {
- header('Content-Type: application/x-www-form-urlencoded');
- print $token;
- print '&oauth_callback_confirmed=true';
- }
-
- function verifyCallback($callback)
- {
- if ($callback == "oob") {
- common_debug("OAuth request token requested for out of band client.");
-
-
-
- return true;
- } else {
- return filter_var($callback, FILTER_VALIDATE_URL);
- }
- }
- }
|