Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
previous fix didn't work, perhaps this one will.
- Loading branch information
1 parent
b182167
commit de0c711
Showing
1 changed file
with
33 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
using System; | ||
using System.Collections.Specialized; | ||
using System.IO; | ||
using System.Net; | ||
|
||
namespace OAuth.Web | ||
{ | ||
public class OAuthTokenResponse | ||
{ | ||
public OAuthTokenResponse(WebResponse httpWebResponse) | ||
public class OAuthTokenResponse | ||
{ | ||
string tokenString; | ||
using(var stream = httpWebResponse.GetResponseStream()) | ||
public OAuthTokenResponse(WebResponse httpWebResponse) | ||
{ | ||
var reader = new StreamReader(stream); | ||
tokenString = reader.ReadToEnd(); | ||
reader.Close(); | ||
} | ||
if(!string.IsNullOrEmpty(tokenString)) | ||
{ | ||
var parts = tokenString.Split('&'); | ||
if(parts.Length>2) | ||
{ | ||
var token = new OAuthToken(); | ||
foreach(var part in parts) | ||
using (var stream = httpWebResponse.GetResponseStream()) | ||
{ | ||
var reader = new StreamReader(stream); | ||
ResponseBody = reader.ReadToEnd(); | ||
reader.Close(); | ||
} | ||
|
||
if (string.IsNullOrEmpty(ResponseBody)) | ||
{ | ||
return; | ||
} | ||
|
||
Items = new NameValueCollection(); | ||
|
||
foreach (string item in ResponseBody.Split('&')) | ||
{ | ||
var tokenparts = part.Split('='); | ||
if(tokenparts.Length==2) | ||
if (item.IndexOf('=') > -1) | ||
{ | ||
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]; | ||
} | ||
string[] temp = item.Split('='); | ||
Items.Add(temp[0], temp[1]); | ||
} | ||
else | ||
{ | ||
Items.Add(item, string.Empty); | ||
} | ||
|
||
} | ||
|
||
|
||
Token = new OAuthToken() { Token = Items["oauth_token"], TokenSecret = Items["oauth_token_secret"] }; | ||
} | ||
} | ||
} | ||
|
||
public OAuthToken Token { get; set; } | ||
} | ||
public string ResponseBody { get; private set; } | ||
|
||
public NameValueCollection Items { get; private set; } | ||
|
||
public OAuthToken Token { get; private set; } | ||
} | ||
} |