IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

redirect_uri always use http not https

Open heavenwing opened this issue 8 years ago • 13 comments

Issue / Steps to reproduce the problem

host identityserver4 server and asp.net core client behind IIS ARR with SSL-offloading add https address into redirecturi for client when login with client , idsvr says unauthorized_client and after add http address into redirecturi, idsvr postback to http not https

I have already add below code into Configure of Startup for idsvr4 and client app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto });

heavenwing avatar Sep 07 '18 08:09 heavenwing

Yeah it's tricky.

https://leastprivilege.com/2017/10/09/new-in-identityserver4-v2-simplified-configuration-behind-load-balancers-or-reverse-proxies/

leastprivilege avatar Sep 07 '18 08:09 leastprivilege

@leastprivilege The PublicOrigin works for fixing the links for well-known configuration, but the redirect url coming back to Identityserver stays http:// instead of https://

heavenwing avatar Sep 11 '18 07:09 heavenwing

Which redirect URI ?

leastprivilege avatar Sep 11 '18 07:09 leastprivilege

Any update on this?

brockallen avatar Sep 14 '18 22:09 brockallen

I'm having this exact same issue, any update? @heavenwing did you get it to work?

victor-ovalle avatar Nov 19 '18 11:11 victor-ovalle

I'm having the same problem.. I enter in my url in the following format in production:

https://www.abc.com

but it redirects to the identityserver4 with the following message:

unauthorized client

With the following error message:

fail: IdentityServer4.Validation.AuthorizeRequestValidator[0] Invalid redirect_uri: http://www.abc.com/connect{ "ClientId": "client_stuff", "ClientName": "client name", "AllowedRedirectUris": [ "https://www.abc.com/connect" ],

If I was to change my ClientRedirectUrl to show as http instead of https, it works. I'm trying to figure this out using fiddler, but it shows all responses as the original request coming as https. So I'm really not sure why identityserver thinks the incoming request from the client is http.

sksallaj82 avatar Dec 07 '18 23:12 sksallaj82

Was able to simply use the answer found here:

https://stackoverflow.com/questions/50468033/redirect-uri-sent-as-http-and-not-https-in-app-running-https

app.UseForwardedHeaders(new ForwardedHeadersOptions
    {
        ForwardedHeaders = ForwardedHeaders.XForwardedProto
    });

sksallaj82 avatar Dec 07 '18 23:12 sksallaj82

That didn't work for me, but I was able to make it work by httpd configuration, Following the instructions here, you will end up with some .conf files for your applications. It's mandatory that you add this to the 443 port VirtualHost:

    ProxyPass / https://127.0.0.1:5001/
    ProxyPassReverse / https://127.0.0.1:5001/
    ServerName [YOUR DOMAIN NAME]:443

    SSLProxyEngine On
    SSLProxyVerify none
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    SSLProxyCheckPeerExpire off

Also, your application must be listening through the port after the localhost IP (5001 in the example). You can do this on Program.cs:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
      WebHost.CreateDefaultBuilder(args)
      .UseUrls("https://localhost:5001", "http://localhost:5010")
          .UseStartup<Startup>();

victor-ovalle avatar Dec 10 '18 08:12 victor-ovalle

@heavenwing did you ever get to the bottom of your issue? i am experiencing same issues with IIS.

morrisond91 avatar Jul 17 '19 13:07 morrisond91

I searched a article with workaround: https://www.linuxidc.com/Linux/2017-06/145177.htm?utm_medium=referral

heavenwing avatar Aug 02 '19 03:08 heavenwing

I explain my problem clearly now . Please re-open this issue. @brockallen

I create a microservice application which include a STS service and mangement console (MC) web. STS service use http protocol and 10103 port, MC web use http protocol and 10102 port.

My microservice app hosted in service fabric cluster, and use IIS ARR as load balancer for this SF cluster. Assigned a domain (sso-login.mydomain.com) to load balancer, route to SF cluster's port 10103. Assigned a domain (sso-mc.mydomain.com) to load balancer , route to SF cluster's port 10102. Binding a SSL certificate into load balancer, but enabled SSL offloading for sso-login.mydomain.com and sso-mc.mydomain.com.

Create a IdentityServer4 client configuration for MC web ( a MVC web application). First, I set "https://sso-mc.mydomain.com" as RedirectUri. When I access MC web with url "https://sso-mc.mydomain.com", once do login action, I will get a error "unauthorized_client". Second, I add "http://sso-mc.mydomain.com" as RedirectUri, "https://sso-mc.mydomain.com" still be kept. When I login at "https://sso-mc.mydomain.com" again, I can see login form from STS service. But after I login successfully , STS service redirect to "http://sso-mc.mydomain.com" instead of "https://sso-mc.mydomain.com".

https://github.com/appsonsf/FabricSSO is my application's source code.

heavenwing avatar Aug 03 '19 14:08 heavenwing

Hi, everyone, I resolved this problem, it's my configuration is not correct.

For IIS ARR, need to add "X-Forwarded-Proto" into header manually, pls reference this answer.

And according to this description, I missed these lines: options.KnownNetworks.Clear(); options.KnownProxies.Clear();

If you don't add it into options, X-Forwarded-Proto would not be forwarded

heavenwing avatar Aug 06 '19 06:08 heavenwing

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 10 '20 22:01 lock[bot]