Hey Matt, try the code below. It works reliably for me.

Make sure you've included:
http://oauth.googlecode.com/svn/code/javascript/oauth.js
http://oauth.googlecode.com/svn/code/javascript/sha1.js
<script type="text/javascript">
        var requestUrl = 'http://...';
        var ck = '...';
        var cks = '...';
        var accessor = {consumerSecret: cks};
        var message = {
            method: "GET",
            action: requestUrl,
            parameters: [
                ['oauth_signature_method', 'HMAC-SHA1'],
                ['oauth_consumer_key', ck],
                ['oauth_version', '1.0'],
                ['xoauth_requestor_id', guid],
                ['format', 'json']
            ]
        };

        OAuth.setTimestampAndNonce(message);
        OAuth.setParameter(message, "oauth_timestamp", OAuth.timestamp
());
        OAuth.SignatureMethod.sign(message, accessor);
        var finalUrl = OAuth.addToURL(message.action,
message.parameters);
</script>


On Jun 17, 8:28 am, Matt Raible <mrai...@gmail.com> wrote:
> Hello,
>
> I'm trying to use the JavaScript API to authenticate with OAuth from a
> GWT application. I've got it working with both Google and Twitter's
> OAuth implementations. However, it seems to fail to sign the URL at
> random. In other words, it works 1 out of 3 times.
>
> I'm using the following makeSignedRequest() function to create the
> signed URL.
>
> Fromhttp://paul.donnelly.org/2008/10/31/2-legged-oauth-javascript-functio...
>
> <script type="text/javascript">
>         var makeSignedRequest = function(ck, cks, ts, encodedurl) {
>             var accessor = { consumerSecret: cks, tokenSecret: ts};
>             var message = { action: encodedurl, method: "GET",
> parameters: [
>                 ["oauth_version","1.0"],
>                 ["oauth_consumer_key",ck]
>             ]};
>
>             OAuth.setTimestampAndNonce(message);
>             OAuth.SignatureMethod.sign(message, accessor);
>
>             var parameterMap = OAuth.getParameterMap(message);
>             var baseStr = OAuth.decodeForm
> (OAuth.SignatureMethod.getBaseString(message));
>             var theSig = "";
>
>             if (parameterMap.parameters) {
>                 for (var item in parameterMap.parameters) {
>                     for (var subitem in parameterMap.parameters[item])
> {
>                         if (parameterMap.parameters[item][subitem] ==
> "oauth_signature") {
>                             theSig = parameterMap.parameters[item][1];
>                             break;
>                         }
>                     }
>                 }
>             }
>
>             var paramList = baseStr[2][0].split("&");
>             paramList.push("oauth_signature=" + theSig);
>             paramList.sort(function(a, b) {
>                 if (a[0] < b[0]) return -1;
>                 if (a[0] > b[0]) return 1;
>                 if (a[1] < b[1]) return  -1;
>                 if (a[1] > b[1]) return 1;
>                 return 0;
>             });
>
>             var locString = "";
>             for (var x in paramList) {
>                 locString += paramList[x] + "&";
>             }
>
>             return baseStr[1][0] + "?" + locString.slice(0,
> locString.length - 1);
>         };
>
>     </script>
>
> Any idea why this could be happening?
>
> Thanks,
>
> Matt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"OAuth" group.
To post to this group, send email to oauth@googlegroups.com
To unsubscribe from this group, send email to oauth+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/oauth?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to