1

我正在科尔多瓦 2.0 中使用 jsoauth 1.3 创建 oauth 连接,谁能告诉我如何以纯文本形式发送消息签名者方法,因为我的服务器仅支持纯文本消息签名者方法。我的 oauth.get 函数工作正常,默认签名者是 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);
                            });
       }
    }
4

1 回答 1

0

好吧,我检查了 jsoauth1.3.4 的代码,jsoauth 不支持纯文本消息签名器。

但如果有人想使用这个我有一个方法(不推荐)

在 jsoauth1.3.4.js的方法中附加以下函数,OAuth.signatureMethod以使 jsoauth 将您的 menthod 识别messagesigner为 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);
    }

未测试

于 2012-09-03T12:32:17.103 回答