HELP !
I’m trying to upgrade may program to support the new oAuth that Google uses in the AdWords.
Using my website I’m able to create an accessToken and an accessTokenSecret for my users and store it in my database.
My problem is when I try to make a soap request later with those credentials.
- Which information do I need to save from the website part? so far I save only the accessToken and the accessTokenSecret. is there anything else?
- How do I use the accessToken, accessTokenSecret and what ever else I’ve saved in order to make a SOAP requests? (please be as “low level” as you can, “just use them in the request header” won’t help me).
Some info on my process:
- Not using the Client Library from Google (too much over head, and so far I didn’t needed them).
- Using the auto-generated SOAP code using VS2005 WSDL on the services I’m using.
- C# code.
Any help would be highly appreciated.
Thanks!
=======================================================================================
As advised, I have extend the GetWebRequest in the following way:
protected override WebRequest GetWebRequest(Uri uri)
{
WebRequest request = base.GetWebRequest(uri);
String token = "XXXXXXXXXXX";//a valid token - changed for here.
String secret = "XXXXXXXXXXXX";//a valid secret - changed for here.
String consumerKey = "anonymous";
String consumerSecret = "anonymous";
String sigMet = "HMAC-SHA1";
String oauth_timestamp = ((DateTime.UtcNow.Ticks - new DateTime(1970, 1, 1).Ticks) / (1000 * 10000)).ToString();
String oauth_nonce = Guid.NewGuid().ToString();
Parameter[] paramArray = new Parameter[]{
new Parameter("oauth_consumer_key", consumerKey),
new Parameter("oauth_token", token),
new Parameter ("oauth_signature_method", sigMet),
new Parameter ("oauth_timestamp", oauth_timestamp),
new Parameter ("oauth_nonce", oauth_nonce)
};
String oauth_signature = CreateHMACSHA1Signature(
request.Method,
uri,
paramArray,
consumerSecret,
secret
);
request.Headers.Add(
"Authorization: OAuth " +
"realm=\"" + "https://www.google.com/" + "\"," +
"oauth_consumer_key=\"" + Parameter.EncodeParameterString(consumerKey) + "\"," +
"oauth_token=\"" + Parameter.EncodeParameterString(token) + "\"," +
"oauth_signature_method=\"" + Parameter.EncodeParameterString(sigMet) + "\"," +
"oauth_signature=\"" + Parameter.EncodeParameterString(oauth_signature) + "\"," +
"oauth_timestamp=\"" + Parameter.EncodeParameterString(oauth_timestamp) + "\"," +
"oauth_nonce=\"" + Parameter.EncodeParameterString(oauth_nonce) + "\""
);
return request;
}
the function CreateHMACSHA1Signature is the same one used to with OAuthGetRequestToken and OAuthAuthorizeToken just fine. but when used with the SOAP I’m getting the following error:
System.Web.Services.Protocols.SoapException: AuthenticationError.OAUTH_TOKEN_HEADER_INVALID @ Service[ServicedAccountService.get]
Any idea why it is?
SUCCESS !!!
I finely found what was wrong, and it was only by a chance.
when creating the signature I’ve used the
request.methodfor the method parameter.The problem with this is that at this moment the method is “GET” but the SOAP mechanisim will change it to “POST” (so it can pass the SOAP parameters) this cause my signature to not work.
the only fix I needed to do is change:
to: