diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-05-07 10:03:12 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-05-07 10:03:12 -0700 |
commit | 957a1811bc69a033a16b00d755a88ceeaf3fced6 (patch) | |
tree | ded97d06a1bec55e0d6bad85d079c2d4b412aa1d /src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs | |
parent | a85cd1c7bb0a22ee08056a19ce60173e3ab8e0e0 (diff) | |
parent | b6dff7d1a6b5b07450b82688ec4727b3e2617ff5 (diff) | |
download | DotNetOpenAuth-957a1811bc69a033a16b00d755a88ceeaf3fced6.zip DotNetOpenAuth-957a1811bc69a033a16b00d755a88ceeaf3fced6.tar.gz DotNetOpenAuth-957a1811bc69a033a16b00d755a88ceeaf3fced6.tar.bz2 |
Merge pull request #140 from dotnetjunky/v4.0
Use cookie to store OAuth token and set it as default mechanism.
Diffstat (limited to 'src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs')
-rw-r--r-- | src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs index f4ad20b..8cb5cc5 100644 --- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs +++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs @@ -76,7 +76,10 @@ namespace DotNetOpenAuth.AspNet.Clients { // Note: Facebook doesn't like us to url-encode the redirect_uri value var builder = new UriBuilder(AuthorizationEndpoint); builder.AppendQueryArgs( - new Dictionary<string, string> { { "client_id", this.appId }, { "redirect_uri", returnUrl.AbsoluteUri }, }); + new Dictionary<string, string> { + { "client_id", this.appId }, + { "redirect_uri", returnUrl.AbsoluteUri } + }); return builder.Uri; } @@ -127,7 +130,7 @@ namespace DotNetOpenAuth.AspNet.Clients { builder.AppendQueryArgs( new Dictionary<string, string> { { "client_id", this.appId }, - { "redirect_uri", returnUrl.AbsoluteUri }, + { "redirect_uri", NormalizeHexEncoding(returnUrl.AbsoluteUri) }, { "client_secret", this.appSecret }, { "code", authorizationCode }, }); @@ -143,6 +146,28 @@ namespace DotNetOpenAuth.AspNet.Clients { } } + /// <summary> + /// Converts any % encoded values in the URL to uppercase. + /// </summary> + /// <param name="url">The URL string to normalize</param> + /// <returns>The normalized url</returns> + /// <example>NormalizeHexEncoding("Login.aspx?ReturnUrl=%2fAccount%2fManage.aspx") returns "Login.aspx?ReturnUrl=%2FAccount%2FManage.aspx"</example> + /// <remarks> + /// There is an issue in Facebook whereby it will rejects the redirect_uri value if + /// the url contains lowercase % encoded values. + /// </remarks> + private static string NormalizeHexEncoding(string url) { + var chars = url.ToCharArray(); + for (int i = 0; i < chars.Length - 2; i++) { + if (chars[i] == '%') { + chars[i + 1] = char.ToUpperInvariant(chars[i + 1]); + chars[i + 2] = char.ToUpperInvariant(chars[i + 2]); + i += 2; + } + } + return new string(chars); + } + #endregion } -} +}
\ No newline at end of file |