5

I'm trying for a purely client side implementation of OAuth for Google APIs using jQuery. i'm making use of oauth.js and sha1.js libraries.

url = "https://www.google.com/accounts/OAuthGetRequestToken";
var accessor = { consumerSecret: 'abc' };
var parameter = {
    oauth_consumer_key:'www.oauthorization.appspot.com',
    oauth_signature_method:'HMAC-SHA1',
    scope:'http://www.google.com/calendar/feeds/private/default/full',
    oauth_timestamp:010111,oauth_nonce:abc,
    oauth_signature:qbc,
    oauth_callback:'http://abc.appspot.com/'
}

OAuth.setTimestampAndNonce(message);
OAuth.SignatureMethod.sign(message, accessor);

$.ajax({
    url: url,
    type: "POST", 
    beforeSend: function( xhr ) {
        xhr.overrideMimeType( 'application/x-www-form-urlencoded' );
        xhr.setRequestHeader('Authorization', 'OAuth');
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    },
    data: parameter
});

On triggering the above AJAX call i get a 405 method not allowed error on firefox and Origin null is not allowed by Access-Control-Allow-Origin. in chrome.

Please help in solving those errors or point me to some working examples of jQuery OAuth implementations for Google.

T I
  • 9,785
  • 4
  • 29
  • 51
  • JSONP won't work in POST. Read more here : http://stackoverflow.com/questions/3860111/how-to-make-a-jsonp-post-request-that-specifies-contenttype-with-jquery –  Apr 03 '12 at 13:42
  • did you make it work? I'm banging my head against the wall trying to use OAuth. – ProblemsOfSumit Feb 28 '14 at 09:31

1 Answers1

0

I tried to do similar things in an extension, and got it working after adding the following permissions into manifest.json.

"permissions": [
    "tabs",
    "https://www.google.com/"
  ],

The original thread was here: Chrome Extension oAuth Request Redirect Page Not Loading

Community
  • 1
  • 1
cyberixae
  • 843
  • 5
  • 15