【问题标题】:How do I set token Secret and consumer secret in OAuth?如何在 OAuth 中设置令牌秘密和消费者秘密?
【发布时间】:2012-04-17 06:41:41
【问题描述】:

在这两个网站上,他们都要求提供令牌秘密和消费者秘密: http://oauth.googlecode.com/svn/code/javascript/example/signature.html http://developer.netflix.com/resources/OAuthTest#instructions

如何以编程方式设置它们:

public void excecuteSigning(String targetURL){
            HttpRequestAdapter requestSig = new HttpRequestAdapter(new HttpGet("http://photos.example.net/photos"));
            HttpParameters requestparameters = new HttpParameters();
            OAuthMessageSigner signer = new HmacSha1MessageSigner();

requestparameters.put(OAuth.OAUTH_CONSUMER_KEY, "dpf43f3p2l4k3l03");        
            requestparameters.put(OAuth.OAUTH_TOKEN, "nnch734d00sl2jdk");
            requestparameters.put(OAuth.OAUTH_NONCE, "kllo9940pd9333jh");
            requestparameters.put(OAuth.OAUTH_TIMESTAMP, "1191242096");
            requestparameters.put(OAuth.OAUTH_SIGNATURE_METHOD, "HMAC-SHA1");
            requestparameters.put(OAuth.OAUTH_VERSION, "1.0");
            requestparameters.put("size", "original");
            requestparameters.put("file", "vacation.jpg");
            String OAUTH_SIG = signer.sign(requestSig, requestparameters);
            System.out.println(OAUTH_SIG);
}

///上面生成这个签名:rYexRY70p6aDDWw0ox0SwERRK2w=

///下面的代码没有生成正确的签名

requestparameters.put("oauth_consumer_secret", "kd94hf93k423kf44");
            requestparameters.put(OAuth.OAUTH_TOKEN_SECRET, "pfkkdhi9sl3r4s00");

【问题讨论】:

    标签: java android oauth-2.0


    【解决方案1】:

    请附上您客户的完整源代码。使用您提供的值,google oauth 测试链接提供此签名 -

    OAuth realm="",oauth_version="1.0",oauth_consumer_key="dpf43f3p2l4k3l03",oauth_token="nnch734d00sl2jdk",oauth_timestamp="1191242096",oauth_nonce="kllo9940pd9333jh",oauth_signature_method="HMAC-SHA1",oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D"
    

    您的客户端生成什么签名值?

    【讨论】:

    • 上面生成这个签名:rYexRY70p6aDDWw0ox0SwERRK2w=
    • 没有 OAuth.OAUTH_CONSUMER_SECRET 参数,如何添加?
    【解决方案2】:
    OAuthMessageSigner signer = new HmacSha1MessageSigner();
         signer.setConsumerSecret(consumerSecret);
         signer.setTokenSecret(tokenSecret);
    

    现在可以正常工作并生成正确的签名。

    【讨论】:

      猜你喜欢
      • 2012-03-10
      • 1970-01-01
      • 1970-01-01
      • 2011-09-08
      • 2015-12-05
      • 2016-03-12
      • 2013-07-04
      • 2013-01-23
      • 2012-07-29
      相关资源
      最近更新 更多