Skip to content

Commit

Permalink
fixing oauth token parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
buildmaster committed Dec 15, 2009
1 parent 11047cf commit b182167
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Core/OAuth.Web/OAuthTokenResponse.cs
@@ -1,3 +1,4 @@
using System;
using System.IO; using System.IO;
using System.Net; using System.Net;


Expand All @@ -17,9 +18,26 @@ public OAuthTokenResponse(WebResponse httpWebResponse)
if(!string.IsNullOrEmpty(tokenString)) if(!string.IsNullOrEmpty(tokenString))
{ {
var parts = tokenString.Split('&'); 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];
}
}

}

} }
} }
} }
Expand Down
11 changes: 11 additions & 0 deletions Tests/OAuth.Web.Tests/HmacSha1SignatureGeneratorSpecifications.cs
Expand Up @@ -16,6 +16,17 @@ public void signature_should_be_created_correctly()
Assert.Equal(HttpUtility.UrlDecode("leyGd1u9SwdDP7189awXNOQoh%2Bo%3D"), signature); 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] [Fact]
public void signature_should_be_created_correctly_for_POST() public void signature_should_be_created_correctly_for_POST()
{ {
Expand Down

0 comments on commit b182167

Please sign in to comment.