当前位置: 首页>>代码示例>>PHP>>正文


PHP OAuthRequest::from_request方法代码示例

本文整理汇总了PHP中OAuthRequest::from_request方法的典型用法代码示例。如果您正苦于以下问题:PHP OAuthRequest::from_request方法的具体用法?PHP OAuthRequest::from_request怎么用?PHP OAuthRequest::from_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OAuthRequest的用法示例。


在下文中一共展示了OAuthRequest::from_request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sign

 /**
  * Sign the request using OAuth. This uses the consumer token and key
  * but 2 legged oauth doesn't require an access token and key. In situations where you want to
  * do a 'reverse phone home' (aka: gadget does a makeRequest to your server
  * and your server wants to retrieve more social information) this is the prefered
  * method.
  *
  * @param string $method the method (get/put/delete/post)
  * @param string $url the url to sign (http://site/social/rest/people/1/@me)
  * @param array $params the params that should be appended to the url (count=20 fields=foo, etc)
  * @param string $postBody for POST/PUT requests, the postBody is included in the signature
  * @return string the signed url
  */
 public function sign($method, $url, $params = array(), $postBody = false, &$headers = array())
 {
     $oauthRequest = OAuthRequest::from_request($method, $url, $params);
     $params = $this->mergeParameters($params);
     foreach ($params as $key => $val) {
         if (is_array($val)) {
             $val = implode(',', $val);
         }
         $oauthRequest->set_parameter($key, $val);
     }
     if ($postBody && strlen($postBody)) {
         if ($this->useBodyHash) {
             $bodyHash = base64_encode(sha1($postBody, true));
             $oauthRequest->set_parameter("oauth_body_hash", $bodyHash);
         }
         if ($this->useBodyHack) {
             $oauthRequest->set_parameter($postBody, '');
         }
     }
     $oauthRequest->sign_request($this->signatureMethod, $this->consumerToken, $this->accessToken);
     if ($postBody && $this->useBodyHack) {
         unset($oauthRequest->parameters[$postBody]);
     }
     $signedUrl = $oauthRequest->to_url();
     return $signedUrl;
 }
开发者ID:nrajput,项目名称:widgetJs,代码行数:39,代码来源:osapiOAuth2Legged.php

示例2: validate_request

 public function validate_request()
 {
     $result = true;
     // Is gadget_url specified?
     if (sizeof($this->gadget_url) > 0) {
         // Does gadget_url match opensocial_app_id?
         if ($this->opensocial_app_url != $this->gadget_url) {
             $result = false;
         }
     }
     // Is this a signed request?
     if (!empty($this->oauth_consumer_key) && !empty($this->oauth_signature)) {
         $request = OAuthRequest::from_request(null, null, array_merge($_GET, $_POST));
         $signature_method = new ServerSignatureMethod();
         $signature_method->set_public_cert($this->oauth_consumer_key);
         // See if signature is valid
         if (!$signature_method->check_signature($request, null, null, $this->oauth_signature)) {
             $result = false;
         }
     } else {
         $result = false;
     }
     // If invalid request, return HTTP 401 response
     if (!$result) {
         header("HTTP/1.0 401 Unauthorized", true, 401);
         echo "<html><body>401 Unauthorized</body></html>";
         die;
     }
     // If valid request, go forward
     return true;
 }
开发者ID:ztp1977,项目名称:opensocial-signed-request-php-library,代码行数:31,代码来源:SignedRequestValidator.php

示例3: handle

 /**
  * Handle a request for temporary OAuth credentials
  *
  * Make sure the request is kosher, then emit a set of temporary
  * credentials -- AKA an unauthorized request token.
  *
  * @param array $args array of arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $datastore = new ApiStatusNetOAuthDataStore();
     $server = new OAuthServer($datastore);
     $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
     $server->add_signature_method($hmac_method);
     try {
         $req = OAuthRequest::from_request();
         // verify callback
         if (!$this->verifyCallback($req->get_parameter('oauth_callback'))) {
             throw new OAuthException("You must provide a valid URL or 'oob' in oauth_callback.", 400);
         }
         // check signature and issue a new request token
         $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') . "'"));
         // return token to the client
         $this->showRequestToken($token);
     } catch (OAuthException $e) {
         common_log(LOG_WARNING, 'API OAuthException - ' . $e->getMessage());
         // Return 401 for for bad credentials or signature problems,
         // and 400 for missing or unsupported parameters
         $code = $e->getCode();
         $this->clientError($e->getMessage(), empty($code) ? 401 : $code, 'text');
     }
 }
开发者ID:ronhuang,项目名称:statusnet,代码行数:36,代码来源:apioauthrequesttoken.php

示例4: execute

 public function execute($filterChain)
 {
     require_once 'OAuth.php';
     $consumer = $token = null;
     try {
         $req = OAuthRequest::from_request();
         list($consumer, $token) = $this->getServer()->verify_request($req);
     } catch (OAuthException $e) {
         // do nothing
     }
     if ($consumer) {
         sfContext::getInstance()->getUser()->setAuthenticated(true);
         $information = Doctrine::getTable('OAuthConsumerInformation')->findByKeyString($consumer->key);
         if ($information) {
             sfContext::getInstance()->getUser()->addCredentials($information->getUsingApis());
         }
         $tokenType = $this->context->getRequest()->getParameter('token_type', 'member');
         if ('member' === $tokenType) {
             $accessToken = Doctrine::getTable('OAuthMemberToken')->findByKeyString($token->key, 'access');
             sfContext::getInstance()->getUser()->setAttribute('member_id', $accessToken->getMember()->id);
         }
     }
     $route = $this->context->getRequest()->getAttribute('sf_route');
     if ($route instanceof opAPIRouteInterface) {
         $actionInstance = $this->context->getController()->getActionStack()->getLastEntry()->getActionInstance();
         $config = $actionInstance->getSecurityConfiguration();
         if (!isset($config['all']['credentials'])) {
             $config['all']['credentials'] = array();
         }
         $config['all']['credentials'] = array_merge($config['all']['credentials'], array($route->getAPIName()));
         $actionInstance->setSecurityConfiguration($config);
     }
     $filterChain->execute();
 }
开发者ID:te-koyama,项目名称:openpne,代码行数:34,代码来源:opCheckOAuthAccessTokenFilter.class.php

示例5: handle

 /**
  * Class handler.
  *
  * @param array $args array of arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $datastore = new ApiStatusNetOAuthDataStore();
     $server = new OAuthServer($datastore);
     $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
     $server->add_signature_method($hmac_method);
     $atok = $app = null;
     // XXX: Insist that oauth_token and oauth_verifier be populated?
     // Spec doesn't say they MUST be.
     try {
         $req = OAuthRequest::from_request();
         $this->reqToken = $req->get_parameter('oauth_token');
         $this->verifier = $req->get_parameter('oauth_verifier');
         $app = $datastore->getAppByRequestToken($this->reqToken);
         $atok = $server->fetch_access_token($req);
     } catch (Exception $e) {
         common_log(LOG_WARNING, 'API OAuthException - ' . $e->getMessage());
         common_debug(var_export($req, true));
         $code = $e->getCode();
         $this->clientError($e->getMessage(), empty($code) ? 401 : $code, 'text');
         return;
     }
     if (empty($atok)) {
         // Token exchange failed -- log it
         $msg = sprintf('API OAuth - Failure exchanging OAuth request token for access token, ' . 'request token = %s, verifier = %s', $this->reqToken, $this->verifier);
         common_log(LOG_WARNING, $msg);
         // TRANS: Client error given from the OAuth API when the request token or verifier is invalid.
         $this->clientError(_('Invalid request token or verifier.'), 400, 'text');
     } else {
         common_log(LOG_INFO, sprintf("Issued access token '%s' for application %d (%s).", $atok->key, $app->id, $app->name));
         $this->showAccessToken($atok);
     }
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:41,代码来源:apioauthaccesstoken.php

示例6: brukar_server_oauth_user

function brukar_server_oauth_user()
{
    $server = _brukar_server();
    $request = OAuthRequest::from_request();
    list($consumer, $token) = $server->verify_request($request);
    $user = user_load($token->uid);
    echo json_encode(array('id' => $user->uid, 'name' => $user->name, 'mail' => $user->mail));
    exit;
}
开发者ID:evenos,项目名称:drupal7-module-brukar,代码行数:9,代码来源:brukar_server.oauth.php

示例7: listenToPreActionEventOauthAccessToken

  static public function listenToPreActionEventOauthAccessToken(sfEvent $event)
  {
    $action = $event['actionInstance'];
    $request = sfContext::getInstance()->getRequest();

    if (!$request->hasParameter('x_auth_mode'))
    {
      return;
    }
    if ($request->getParameter('x_auth_mode') !== 'client_auth')
    {
      return;
    }

    $params = $request->getPostParameters();
    unset($params['x_auth_mode']);

    $formParams = array();
    foreach ($params as $key => $value)
    {
      if (strpos($key, 'x_auth_') === 0)
      {
         $formParams[mb_substr($key, 7)] = $value;
      }
    }

    $authForm = sfContext::getInstance()->getUser()->getAuthForm();
    $authForm->disableCSRFProtection();
    $authForm->bind($formParams);
    if (!$authForm->isValid())
    {
      return;
    }

    // request token
    $authRequest = OAuthRequest::from_request();
    $token = opXAuthPluginToolkit::getServer($action)->fetch_request_token($authRequest);
 
    // authorize token
    $information = opXAuthPluginToolkit::getTokenTable()->findByKeyString($token->key);
    $action->forward404Unless($information);

    $callback = $authRequest->get_parameter('oauth_callback');
    $information->setCallbackUrl($callback ? $callback : 'oob');
    $information->setMemberId(sfContext::getInstance()->getUser()->getMemberId());
    $information->save();

    // accsess token
    $consumer = new OAuthConsumer($authRequest->get_parameter('oauth_consumer_key'));
    $token = opXAuthPluginToolkit::getDataStore()->new_access_token($token, $consumer);

    echo (string)$token;

    exit;
  }
开发者ID:nothan,项目名称:opXAuthPlugin,代码行数:55,代码来源:opXAuthPluginObserver.class.php

示例8: handleOAuthBodyPOST

function handleOAuthBodyPOST($oauth_consumer_key, $oauth_consumer_secret) 
{
    $request_headers = OAuthUtil::get_headers();
    // print_r($request_headers);

    // Must reject application/x-www-form-urlencoded
    if ($request_headers['Content-type'] == 'application/x-www-form-urlencoded' ) {
        throw new Exception("OAuth request body signing must not use application/x-www-form-urlencoded");
    }

    if (@substr($request_headers['Authorization'], 0, 6) == "OAuth ") {
        $header_parameters = OAuthUtil::split_header($request_headers['Authorization']);

        // echo("HEADER PARMS=\n");
        // print_r($header_parameters);
        $oauth_body_hash = $header_parameters['oauth_body_hash'];
        // echo("OBH=".$oauth_body_hash."\n");
    }

    if ( ! isset($oauth_body_hash)  ) {
        throw new Exception("OAuth request body signing requires oauth_body_hash body");
    }

    // Verify the message signature
    $store = new TrivialOAuthDataStore();
    $store->add_consumer($oauth_consumer_key, $oauth_consumer_secret);

    $server = new OAuthServer($store);

    $method = new OAuthSignatureMethod_HMAC_SHA1();
    $server->add_signature_method($method);
    $request = OAuthRequest::from_request();

    global $LastOAuthBodyBaseString;
    $LastOAuthBodyBaseString = $request->get_signature_base_string();
    // echo($LastOAuthBodyBaseString."\n");

    try {
        $server->verify_request($request);
    } catch (Exception $e) {
        $message = $e->getMessage();
        throw new Exception("OAuth signature failed: " . $message);
    }

    $postdata = file_get_contents('php://input');
    // echo($postdata);

    $hash = base64_encode(sha1($postdata, TRUE));

    if ( $hash != $oauth_body_hash ) {
        throw new Exception("OAuth oauth_body_hash mismatch");
    }

    return $postdata;
}
开发者ID:anilch,项目名称:Personel,代码行数:55,代码来源:OAuthBody.php

示例9: access_token

 /**
  * Exchange the request token for an access token
  *
  * Endpoint: /auth/access_token
  */
 public static function access_token()
 {
     try {
         $request = OAuthRequest::from_request();
         $result = WPOAuthProvider::access_token($request);
         header('Content-Type: application/x-www-form-urlencoded');
         echo $result;
     } catch (OAuthException $e) {
         throw new Exception($e->getMessage(), 401);
     }
 }
开发者ID:rmccue,项目名称:WordPressOAuthProvider,代码行数:16,代码来源:example-implementer.php

示例10: api_content

function api_content(&$a)
{
    if ($a->cmd == 'api/oauth/authorize') {
        /* 
         * api/oauth/authorize interact with the user. return a standard page
         */
        $a->page['template'] = "minimal";
        // get consumer/client from request token
        try {
            $request = OAuthRequest::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 OAuthConsumer($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=" . OAuthUtil::urlencode_rfc3986($params['oauth_token']) . "&oauth_verifier=" . OAuthUtil::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();
}
开发者ID:msooon,项目名称:hubzilla,代码行数:54,代码来源:api.php

示例11: handle

 /**
  * Class handler.
  * 
  * @param array $args array of arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     try {
         common_remove_magic_from_request();
         $req = OAuthRequest::from_request();
         $server = omb_oauth_server();
         $token = $server->fetch_request_token($req);
         print $token;
     } catch (OAuthException $e) {
         $this->serverError($e->getMessage());
     }
 }
开发者ID:Br3nda,项目名称:laconica,代码行数:20,代码来源:requesttoken.php

示例12: executeAccessToken

 public function executeAccessToken(sfWebRequest $request)
 {
     require_once 'OAuth.php';
     $requestToken = $request->getParameter('oauth_token');
     $this->information = $this->getTokenTable()->findByKeyString($requestToken);
     $this->forward404Unless($this->information);
     $this->forward404Unless($this->information->getIsActive());
     $this->forward404Unless($this->information->getVerifier() === $request->getParameter('oauth_verifier'));
     $authRequest = OAuthRequest::from_request();
     $token = $this->getServer()->fetch_access_token($authRequest);
     $this->information->delete();
     $this->getResponse()->setContent((string) $token);
     return sfView::NONE;
 }
开发者ID:Kazuhiro-Murota,项目名称:OpenPNE3,代码行数:14,代码来源:opOAuthTokenAction.class.php

示例13: authorize

 public function authorize($params)
 {
     if (!isset($_SESSION['id'])) {
         header("Location: /login?redirect=" . urlencode($_SERVER['REQUEST_URI']));
         die;
     }
     $request = OAuthRequest::from_request();
     $token = $request->get_parameter('oauth_token');
     $callback = $request->get_parameter('oauth_callback');
     if (!$token) {
         $this->sendServerError('400', 'Bad Request - missing oauth_token');
         return;
     }
     $this->template('oauth/authorize.php', array('oauth_token' => $token, 'oauth_callback' => $callback));
 }
开发者ID:vuxuandung,项目名称:Partuza-bundle,代码行数:15,代码来源:oauth.php

示例14: handle

 function handle($args)
 {
     parent::handle($args);
     try {
         common_remove_magic_from_request();
         $req = OAuthRequest::from_request();
         # Note: server-to-server function!
         $server = omb_oauth_server();
         list($consumer, $token) = $server->verify_request($req);
         if ($this->save_notice($req, $consumer, $token)) {
             print "omb_version=" . OMB_VERSION_01;
         }
     } catch (OAuthException $e) {
         $this->serverError($e->getMessage());
         return;
     }
 }
开发者ID:Br3nda,项目名称:laconica,代码行数:17,代码来源:postnotice.php

示例15: handle

 /**
  * Class handler.
  *
  * @param array $args array of arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $datastore = new ApiStatusNetOAuthDataStore();
     $server = new OAuthServer($datastore);
     $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
     $server->add_signature_method($hmac_method);
     try {
         $req = OAuthRequest::from_request();
         $token = $server->fetch_request_token($req);
         print $token;
     } catch (OAuthException $e) {
         common_log(LOG_WARNING, 'API OAuthException - ' . $e->getMessage());
         header('HTTP/1.1 401 Unauthorized');
         header('Content-Type: text/html; charset=utf-8');
         print $e->getMessage() . "\n";
     }
 }
开发者ID:sukhjindersingh,项目名称:PHInest-Solutions,代码行数:25,代码来源:apioauthrequesttoken.php


注:本文中的OAuthRequest::from_request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。