I am trying to get OAuth to work with the .NET library for the Google Data API. Unfortunately, whenever I call GetUnauthorizedRequestToken, I get a 400 Bad Response error. Here is my code ...
OAuthParameters parameters = new OAuthParameters() { ConsumerKey = DOMAIN_NAME, ConsumerSecret = SECRET_KEY, Scope = "https://docs.google.com/feeds/", Callback = Request.RawUrl, SignatureMethod = "HMAC-SHA1" }; OAuthUtil.GetUnauthorizedRequestToken(parameters);
As far as I know, I correctly follow the instructions here: http://code.google.com/apis/gdata/docs/auth/oauth.html
Any help with this issue would be greatly appreciated!
EDIT: 9/10/2011 11:56 PM PST
First of all, many thanks for the comments!
So, I played around a bit and got an unauthorized request token, but OAuth still doesn't work ... here is a more complete code dump: - \
string token = Request["oauth_token"]; if (!String.IsNullOrEmpty(token)) { OAuthParameters tParams = new OAuthParameters() { ConsumerKey = DOMAIN_NAME, ConsumerSecret = SECRET_KEY, Scope = S_SCOPE, Callback = S_CALLBACK, SignatureMethod = "HMAC-SHA1" }; tParams.Verifier = Request["oauth_verifier"]; tParams.Token = token; try { // http://code.google.com/apis/gdata/docs/auth/oauth.html // 1. Extract token from the callback URL //OAuthUtil.UpdateOAuthParametersFromCallback(Request.Url.Query, parameters); // 2. Upgrade to an access token OAuthUtil.GetAccessToken(tParams); string accessToken = tParams.Token; string accessTokenSecret = tParams.TokenSecret; Session["sp"] = tParams; // don't worry, we don't even get here yet return RedirectToAction("List"); } catch (System.Net.WebException ex) { // print out tons of stuff (removed for sanity) } //... and start over again } try { OAuthParameters parameters = new OAuthParameters() { ConsumerKey = DOMAIN_NAME, ConsumerSecret = SECRET_KEY, Scope = S_SCOPE, Callback = S_CALLBACK, SignatureMethod = "HMAC-SHA1" }; OAuthUtil.GetUnauthorizedRequestToken(parameters); string approvalPageUrl = OAuthUtil.CreateUserAuthorizationUrl(parameters); ViewBag.AuthUrl = approvalPageUrl; } catch (System.Net.WebException ex) { // print out more stuff }
and this is the error that I see (slightly modified to delete sensitive data, however, I left all the characters as they are in case someone thinks this is an encoding error):
X-Content-Type-Options = nosniff X-XSS-Protection = 1; mode=block Content-Length = 386 Cache-Control = private, max-age=0 Content-Type = text/plain; charset=UTF-8 Date = Sun, 11 Sep 2011 06:53:26 GMT Expires = Sun, 11 Sep 2011 06:53:26 GMT Server = GSE /accounts/OAuthGetAccessToken signature_invalid base_string:GET&https%3A%2F%2Fwww.google.com%2Faccounts%2FOAuthGetAccessToken&oauth_consumer_key%3Dmydomain.com%26oauth_nonce%3D4432dc4bd59b4ea0b133ea52cb450062%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1315724016%26oauth_token%3D4%252FGeEWOLvQL_eGlj8zAdrzi7YPhmhS%26oauth_verifier%3DMkGYPy8qeZPRg7gLKKXsYIiM%26oauth_version%3D1.0 Callback = http://mydomain.com/auth ConsumerKey = mydomain.com ConsumerSecret = RxGavGhuXi92sy3F-Q3DKcY_ Nonce = 4430dc4bd59b4ea3b133ea52cb450062 Scope = https://docs.google.com/feeds SignatureMethod = HMAC-SHA1 Timestamp = 1315724016 Token = 4/GeAWOLvQL_eGlj1zEerzi7YPhmhS TokenSecret = Verifier = MkXLPy8qeZARq7aLKXKsYIiM
2F% 2Fwww.google.com% 2Faccounts% 2FOAuthGetAccessToken & oauth_consumer_key% 3Dmydomain.com% 26oauth_nonce% 3D4432dc4bd59b4ea0b133ea52cb450062% 26oauth_signature_method% 3DHMAC-SHA1% 26oauth_timestamp% 3D1315724016% 26oauth_token% 3D4% 252FGeEWOLvQL_eGlj8zAdrzi7YPhmhS% 26oauth_verifier% 3DMkGYPy8qeZPRg7gLKKXsYIiM% 26oauth_version% 3D1. X-Content-Type-Options = nosniff X-XSS-Protection = 1; mode=block Content-Length = 386 Cache-Control = private, max-age=0 Content-Type = text/plain; charset=UTF-8 Date = Sun, 11 Sep 2011 06:53:26 GMT Expires = Sun, 11 Sep 2011 06:53:26 GMT Server = GSE /accounts/OAuthGetAccessToken signature_invalid base_string:GET&https%3A%2F%2Fwww.google.com%2Faccounts%2FOAuthGetAccessToken&oauth_consumer_key%3Dmydomain.com%26oauth_nonce%3D4432dc4bd59b4ea0b133ea52cb450062%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1315724016%26oauth_token%3D4%252FGeEWOLvQL_eGlj8zAdrzi7YPhmhS%26oauth_verifier%3DMkGYPy8qeZPRg7gLKKXsYIiM%26oauth_version%3D1.0 Callback = http://mydomain.com/auth ConsumerKey = mydomain.com ConsumerSecret = RxGavGhuXi92sy3F-Q3DKcY_ Nonce = 4430dc4bd59b4ea3b133ea52cb450062 Scope = https://docs.google.com/feeds SignatureMethod = HMAC-SHA1 Timestamp = 1315724016 Token = 4/GeAWOLvQL_eGlj1zEerzi7YPhmhS TokenSecret = Verifier = MkXLPy8qeZARq7aLKXKsYIiM