Browse files

fixing oauth token parsing

  • Loading branch information...
1 parent 11047cf commit b1821676be7f7fa9ed378da8c5a919bbe72be8db @buildmaster committed Dec 16, 2009
View
22 Core/OAuth.Web/OAuthTokenResponse.cs
@@ -1,3 +1,4 @@
+using System;
using System.IO;
using System.Net;
@@ -17,9 +18,26 @@ public OAuthTokenResponse(WebResponse httpWebResponse)
if(!string.IsNullOrEmpty(tokenString))
{
var parts = tokenString.Split('&');
- if(parts.Length==2)
+ if(parts.Length>2)
{
- Token = new OAuthToken {Token = parts[0].Trim().Replace("oauth_token=",""), TokenSecret = parts[1].Trim().Replace("oauth_token_secret=","")};
+ var token = new OAuthToken();
+ foreach(var part in parts)
+ {
+ var tokenparts = part.Split('=');
+ if(tokenparts.Length==2)
+ {
+ if(tokenparts[0].Equals("oauth_token",StringComparison.OrdinalIgnoreCase))
+ {
+ token.Token = tokenparts[1];
+ }
+ else if (tokenparts[0].Equals("oauth_token_secret", StringComparison.OrdinalIgnoreCase))
+ {
+ token.TokenSecret = tokenparts[1];
+ }
+ }
+
+ }
+
}
}
}
View
11 Tests/OAuth.Web.Tests/HmacSha1SignatureGeneratorSpecifications.cs
@@ -16,6 +16,17 @@ public void signature_should_be_created_correctly()
Assert.Equal(HttpUtility.UrlDecode("leyGd1u9SwdDP7189awXNOQoh%2Bo%3D"), signature);
}
+
+ //[Fact]
+
+ //public void signature_should_be_created_correctly_2()
+ //{
+ // var signatureGenerator = new HmacSha1SignatureGenerator();
+ // var signature = signatureGenerator.Generate("kd94hf93k423kf44&", "GET&https%3A%2F%2Fapi.xero.com%2Foauth%2FRequestToken&oauth_consumer_key%3DMTY3NJMYNWZINWI3NGU3MWFLZWRHZT%26oauth_nonce%3D4b0535c1c1283%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1258632641%26oauth_version%3D1.0");
+ // Assert.Equal(HttpUtility.UrlDecode("Nj9ISPVyWtZ0%2Bq41mPOicAvC6RU%3D"), signature);
+
+ //}
+
[Fact]
public void signature_should_be_created_correctly_for_POST()
{

0 comments on commit b182167

Please sign in to comment.