簡體   English   中英

如何在OAuth中設置令牌密鑰和消費者密鑰?

[英]How do I set token Secret and consumer secret in OAuth?

在這兩個網站上,他們都要求提供令牌密鑰和消費者密鑰: 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");

請提供您客戶的完整源代碼。 使用您提供的值,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"

您的客戶產生什么簽名值?

OAuthMessageSigner signer = new HmacSha1MessageSigner();
     signer.setConsumerSecret(consumerSecret);
     signer.setTokenSecret(tokenSecret);

現在可以正常工作並生成正確的簽名。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM