I am trying to get OAuth working with the .NET library for 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 am correctly following the instructions here: http://code.google.com/apis/gdata/docs/auth/oauth.html
Any help with this problem would be much appreciated!
EDIT: 9/10/2011 11:56 PM PST
First of all, thank you so much for the comments!
So I've fiddled around a bit and got the Unauthorized Request Token working, but OAuth is still not really working... 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 I am seeing (slightly modified to remove sensitive data, however I left all the symbols as-is 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