From b1821676be7f7fa9ed378da8c5a919bbe72be8db Mon Sep 17 00:00:00 2001 From: Owen Evans Date: Wed, 16 Dec 2009 09:40:03 +1300 Subject: [PATCH] fixing oauth token parsing --- Core/OAuth.Web/OAuthTokenResponse.cs | 22 +++++++++++++++++-- ...macSha1SignatureGeneratorSpecifications.cs | 11 ++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Core/OAuth.Web/OAuthTokenResponse.cs b/Core/OAuth.Web/OAuthTokenResponse.cs index 6c61ec8..2ca332d 100644 --- a/Core/OAuth.Web/OAuthTokenResponse.cs +++ b/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]; + } + } + + } + } } } diff --git a/Tests/OAuth.Web.Tests/HmacSha1SignatureGeneratorSpecifications.cs b/Tests/OAuth.Web.Tests/HmacSha1SignatureGeneratorSpecifications.cs index b51523a..d45104f 100644 --- a/Tests/OAuth.Web.Tests/HmacSha1SignatureGeneratorSpecifications.cs +++ b/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() {