-
Notifications
You must be signed in to change notification settings - Fork 598
Makes FacebookAuthenticationHandler respect Options.UserInformationEndpoint #366
Conversation
Hi @bchavez, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution! The agreement was validated by .NET Foundation and real humans are currently evaluating your PR. TTYL, DNFBOT; |
Do you think you could add a test verifying your fix to this class? |
Sure, no problem, be back in a few. 👍 |
var endpoint = Options.UserInformationEndpoint; | ||
var accessToken = "access_token=" + UrlEncoder.UrlEncode(tokens.AccessToken); | ||
|
||
endpoint += endpoint.Contains("?") ? "&" : "?"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: you can also use QueryHelpers.AddQueryString
👪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PinpointTownes Yeah, I was thinking about using a helper to build the query string, but wasn't sure about @HaoK 's thoughts on the subject since the other Auth providers don't do anything like that. I was exercising some caution not to move so much code. @HaoK , would you prefer that I use QueryHelpers
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah please use QueryHelpers, the manual query string manipulation stood out when I saw the change as well.
@HaoK @PinpointTownes Should be ok now. My new Unit Test is passing. |
@@ -51,10 +51,10 @@ public FacebookAuthenticationHandler(HttpClient httpClient) | |||
|
|||
protected override async Task<AuthenticationTicket> CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens) | |||
{ | |||
var endpoint = Options.UserInformationEndpoint + "?access_token=" + UrlEncoder.UrlEncode(tokens.AccessToken); | |||
var endpoint = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", UrlEncoder.UrlEncode(tokens.AccessToken)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using QueryHelpers.AddQueryString
, key
and value
are automatically url-encoded for you.
Pre-encoding them will result in a terrible double encoding. It's probably not a big deal since access tokens issued by Facebook only use alphanumerical chars, but it's not a guarantee and it may change in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PinpointTownes Ah, thank you, I totally missed that. I've updated my branch accordingly. Thanks so much.
1f8368e now voids double URL encoding with |
You're welcome, @bchavez! 😄 On a side note, it seems that Facebook now supports the Sadly, I can't find any reference 😢 |
@PinpointTownes Sounds great, hoping they publish a reference soon rather than passing Slightly off topic, but I tried to run the unit test again just to make sure everything was okay. But ran into a problem. Everything was working prior to opening the project today. After opening this project in VS2015 RTM, waited for everything to load, then saw the "package manager" console go crazy like it was doing some updates to
:( |
I guess that's due to the fact you're using a beta5 DNX runtime while contributing on beta7 packages 😄
|
I see. Thanks @PinpointTownes. My pull-request for Facebook here will eventually propagate to ASP.NET 4 too right? Ultimately, v4 is what I'm looking to fix at the moment. Thanks for all your help. 👍 |
If by "ASP.NET 4" you mean Katana (aka |
Oh noes, so there is no way to fix this Nuget package? https://www.nuget.org/packages/Microsoft.Owin.Security.Facebook/ :( :( :( |
Absolutely no way, I'm afraid. I guess the only reason the ASP.NET team would update a Katana package would be to fix a major security flaw. |
|
Merged. |
Looks like the 👊 |
Fixes #365