1

I am creating a oauth connectivity using jsoauth 1.3 in cordova 2.0 can anyone tell me how to sent message signer method as plain text because my server only support plain text message signer method. my oauth.get function is working properly bur the default signer is HMAC-SHA1

this is my code

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);
                            });
       }
    }
SproutinGeek
  • 327
  • 3
  • 19
  • Whe I uncomment the line signatureMethod: 'PLAINTEXT' in the above code I get an error in the log [link] (09-01 16:37:42.120: E/Web Console(16950): Uncaught TypeError: Object # has no method 'PLAINTEXT' at file:///android_asset/www/jsOAuth-1.3.4.js:433) – SproutinGeek Sep 01 '12 at 11:10

1 Answers1

0

Well I checked the code of jsoauth1.3.4 and the Plaintext messagesigner is not supported by jsoauth.

but still if somebody wants to use this I have a method (non-recommended)

append the below function in the OAuth.signatureMethod method in jsoauth1.3.4.js to make the jsoauth recognize your messagesigner menthod as 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);
    }

Not Tested

Rostyslav Dzinko
  • 39,424
  • 5
  • 49
  • 62
SproutinGeek
  • 327
  • 3
  • 19