10
Host where my application is hosted uses ARR to redirect all pages to Https.
The problem is that the way the code of the asp.net mvc understands that the requisition is http, even though https.
When I see the URL that goes to Google authentication is like this:
&redirect_uri=http%3A%2F%mydomain.com\signing-google
So I’m trying to redirect to Google by changing "at hand" to https.
I’ve tried that:
public class ChallengeResult : HttpUnauthorizedResult
{
...
public override void ExecuteResult(ControllerContext context)
{
var properties = new AuthenticationProperties { RedirectUri = RedirectUri };
if (UserId != null)
properties.Dictionary[XsrfKey] = UserId;
var owin = context.HttpContext.GetOwinContext();
owin.Request.Scheme = "https"; //hotfix
owin.Authentication.Challenge(properties, LoginProvider);
}
}
and this:
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = Secrets.GoogleClientId,
ClientSecret = Secrets.GoogleClientSecret,
Provider = new GoogleOAuth2AuthenticationProvider()
{
OnApplyRedirect = async context =>
{
string redirect = context.RedirectUri;
redirect = redirect.Replace("redirect_uri=http", "redirect_uri=https");
context.Response.Redirect(redirect);
}
}
});
Both ways work and Google can redirect to my application again, but the moment I get the user data it returns null.
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
if (string.IsNullOrEmpty(returnUrl))
returnUrl = "~/";
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
//sempre retorna null se eu mudo de http para https "na mão"
}
I tried to see the implementation of the method GetExternalLoginInfoAsync(), but I haven’t found why to always return null when I do that workaround.
Have you tried any of the solutions given in this reply?(note: link to SOEN)
– Omni
You’ve already solved something?
– PauloHDSousa
In my case, the only solution was to talk to the infra sector and change the ARR configuration. So I don’t know what to do with this question (since there was no solution).
– Fernando Mondo