代码之家  ›  专栏  ›  技术社区  ›  navitronic

oAuth在PHP中提出两条腿的请求

  •  2
  • navitronic  · 技术社区  · 16 年前

    我使用的是这里的PHP库: http://code.google.com/p/oauth-php/ 而且在网上似乎没有任何文档可以用来处理2条腿的请求。

    • $消费者密钥 必须是空字符串
    • $消费者秘密 - 必须是空字符串
    • - 我的登录名
    • $access_令牌_秘密 生成的应用程序令牌

    我希望能够向:

    http://foo.com/api/test/whoami
    

    有人知道如何使用php库来实现这个目标吗?还是有更好的方法来实现这样一个简单的2条腿的调用?

    救命啊!? :)

    2 回复  |  直到 16 年前
        2
  •  0
  •   Muhammad Reda    10 年前

    您只需要使用者密钥和使用者机密就可以发出授权的两条腿oauth请求。

    下载 OAuthConsumer . (评论全班 OAuthException

    代码示例:

    require_once 'OAuth.php';
    
    $signatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
    $consumerKey = 'abc';
    $consumerSecret = 'def';
    $httpMethod = 'GET';
    $url = 'http://path/to/endpoint';
    $requestFields = array();
    
    $oauthConsumer = new OAuthConsumer($consumerKey, $consumerSecret, NULL);
    $oauthRequest = OAuthRequest::from_consumer_and_token($oauthConsumer, NULL, $httpMethod, $url, $requestFields);
    $oauthRequest->sign_request($signatureMethod, $oauthConsumer, NULL);
    
    推荐文章