我正在使用cordova 2.0中的jsoauth 1.3创建oauth连接,任何人都可以告诉我如何将消息签名者方法作为纯文本发送,因为我的服务器只支持纯文本消息签名者方法。我的oauth.get函数工作正常bur默认签名者是HMAC-SHA1
这是我的代码
function oauthStart1() {
var oauth;
var requestParams;
var options = {
consumerKey : 'blahblah',
consumerSecret : 'blahblah',
callbackUrl : 'stx://blahblah'
// signatureMethod: 'PLAIN_TEXT'
};
// information in
var twitterKey = "twttrKey"; // what we will store our twitter user information in
// our storedAccessData and Raw Data
var storedAccessData, rawData = localStorage.getItem(twitterKey);
// First thing we need to do is check to see if we already have the user saved!
if(localStorage.getItem(twitterKey) != null){
alert("localStorage not null")
storedAccessData = JSON.parse(rawData); // Parse our JSON object
options.accessTokenKey = storedAccessData.accessTokenKey; // This is saved when they first sign in
options.accessTokenSecret = storedAccessData.accessTokenSecret; // this is saved when they first sign in
localStorage.clear()
}
else{
alert("localStorage is null" );
oauth = OAuth(options);
alert(JSON.stringify(oauth));
oauth
.get(
'http://231.123.123.243:8081/blahblah/oauth/initiate.action',
function(data) {
requestParams = data.text;
alert("requestParams" + requestParams);
window.plugins.childBrowser.showWebPage('http://231.123.123.243:8081/blahblah/oauth/authorize.action?'
+ data.text, { showLocationBar: true}); // page
window.plugins.childBrowser.onLocationChange = function(loc) {
if(loc.indexOf(options.callbackUrl) >=0 ){
window.plugins.childBrowser.close();
var index, verifier = '';
var params = loc.substr(loc.indexOf('?') + 1);
alert("params"+ params);
params = params.split('&');
for (var i = 0; i < params.length; i++) {
var y = params[i].split('=');
if(y[0] === 'oauth_verifier') {
verifier = y[1];
}
}
oauth.get('http://231.123.123.243:8081/blahblah/oauth/authorize.action?oauth_verifier='+verifier+'&'+requestParams,
function(data) {
alert("verify Success" + data)
var accessParams = {};
var qvars_tmp = data.text.split('&');
for (var i = 0; i < qvars_tmp.length; i++) {
var y = qvars_tmp[i].split('=');
accessParams[y[0]] = decodeURIComponent(y[1]);
}
var accessData = {};
accessData.accessTokenKey = accessParams.oauth_token;
accessData.accessTokenSecret = accessParams.oauth_token_secret;
alert("fine")
//localStorage.setItem(twitterKey, JSON.stringify(accessData));
},
function(data) {
alert("varify error");
}
);
}
};
}, function(data) {
alert("ERROR: " + data);
});
}
}
答案 0 :(得分:0)
我检查了jsoauth1.3.4的代码,jsoauth不支持纯文本消息标识符。
但是如果有人想要使用它,我有一个方法(非推荐)
在jsoauth1.3.4.js的OAuth.signatureMethod
方法中附加以下函数,以使jsoauth将您的messagesigner
menthod识别为PLAIN_TEXT
'PLAIN_TEXT': function (consumer_secret, token_secret) {
var passphrase, signature, encode = OAuth.urlEncode;
consumer_secret = encode(consumer_secret);
token_secret = encode(token_secret || '');
passphrase = consumer_secret + '&' + token_secret;
return global.btoa(passphrase);
}
未经测试