Security icon indicating copy to clipboard operation
Security copied to clipboard

signin-oidc is pending when authorize is finished [ubuntu16.04]

Open atpyk opened this issue 9 years ago • 31 comments

Everything work fine on my local(windows platform). When I deploy them onto linux(ubuntu16.04), the issue raised.

I can't get any response after I sign in successfully, it always loading until receive a blank page.

atpyk avatar Feb 09 '17 03:02 atpyk

What's the status code and headers for that 'blank page'? If it's a 500 then you should check your server logs for an error.

Tratcher avatar Feb 09 '17 04:02 Tratcher

Snapshot1: It takes too long time that is about 15mins.

Snapshot2:

atpyk avatar Feb 09 '17 05:02 atpyk

It's my configuration for OpenId middle ware:

app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
            {
                AuthenticationScheme = "oidc",
                SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme,
                AutomaticAuthenticate = false,

                Authority = Settings["AuthorityUrl"],
                RequireHttpsMetadata = false,

                ClientId = "*****.dashboard",
                ClientSecret = "secret",
                ResponseType = OpenIdConnectResponseType.CodeIdToken,
                Scope = { "basicinfo **** ***" },
                GetClaimsFromUserInfoEndpoint = true,
                SaveTokens = true,

                Events = new OpenIdConnectEvents()
                {
                    OnMessageReceived = context =>
                    {
                        if (context.ProtocolMessage.Error != null)
                        {
                            context.SkipToNextMiddleware();
                            context.Response.Redirect("/Home/Error");
                        }

                        return Task.FromResult(0);
                    },

                    OnRemoteFailure = context =>
                    {
                        if (context.Failure is OpenIdConnectProtocolException)
                        {
                            context.Response.Redirect("/Home/AccessDenied");
                            context.HandleResponse();
                            return Task.FromResult(0);
                        }
                        else
                        {
                            context.SkipToNextMiddleware();
                            context.Response.Redirect("/Home/Error");
                        }

                        throw context.Failure;
                    }
                }
            });

atpyk avatar Feb 09 '17 05:02 atpyk

Likely unrelated, but

context.SkipToNextMiddleware();
context.Response.Redirect("/Home/Error");

is a nonsensical combination. You should use HandleResponse() with Redirect.

Tratcher avatar Feb 09 '17 05:02 Tratcher

Also, don't re-throw the exception in OnRemoteFailure.

Tratcher avatar Feb 09 '17 05:02 Tratcher

I forget to remove "OnMessageReceived" section, thanks for your mention.

atpyk avatar Feb 09 '17 06:02 atpyk

The issue still have.

atpyk avatar Feb 09 '17 08:02 atpyk

@atpyk we recommend enabling logging so that it'll be easier to see at what point the server is taking too long. If you could do that and share your logs we can investigate further.

Eilon avatar Feb 10 '17 20:02 Eilon

I report this issue to IdentityServer4 too: 730

No error log in Idsvr side, the client portal side's log is:

fail: Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectMiddleware[17]
Exception occurred while processing message.
Microsoft.IdentityModel.Tokens.SecurityTokenExpiredException: IDX10223: Lifetime validation failed. The token is expired.
ValidTo: '01/22/2017 01:00:59'
Current time: '01/22/2017 01:05:59'.
at Microsoft.IdentityModel.Tokens.Validators.ValidateLifetime(Nullable1 notBefore, Nullable1 expires, SecurityToken securityToken, TokenValidationParameters validationParameters)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateLifetime(Nullable1 notBefore, Nullable1 expires, JwtSecurityToken securityToken, TokenValidationParameters validationParameters)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateTokenPayload(JwtSecurityToken jwt, TokenValidationParameters validationParameters)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateToken(String token, TokenValidationParameters validationParameters, SecurityToken& validatedToken)
at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.ValidateToken(String idToken, AuthenticationProperties properties, TokenValidationParameters validationParameters, JwtSecurityToken& jwt)
at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.d__20.MoveNext()
info: Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectMiddleware[4]
Error from RemoteAuthentication: IDX10223: Lifetime validation failed. The token is expired.
ValidTo: '01/22/2017 01:00:59'
Current time: '01/22/2017 01:05:59'..

atpyk avatar Feb 13 '17 09:02 atpyk

ValidTo: '01/22/2017 01:00:59' Current time: '01/22/2017 01:05:59'

I'm really tempted to say that @leastprivilege already gave you the right answer: https://github.com/IdentityServer/IdentityServer4/issues/730#issuecomment-274463452.

That said, you likely have another issue (with your proxy?), as the request is not supposed to hang when it's rejected by the OIDC middleware.

kevinchalet avatar Feb 13 '17 10:02 kevinchalet

We use nginx to deploy the Idsvr4 and webportal on the same sever, and just to do the easy setting for mapping to the corresponding ports, Idsvr4 is 5000; webportal is 5005. Did you guys reproduce this issue by nginx. That's a very tough issue.

atpyk avatar Feb 16 '17 07:02 atpyk

@atpyk can you try changing the OnRemoteFailure handler to check for an additional exception type?

Currently it checks context.Failure is OpenIdConnectProtocolException, but in this case you might want to also handle a Microsoft.IdentityModel.Tokens.SecurityTokenExpiredException.

Also, please check the else class of the OnRemoteFailure where it currently has these two lines:

context.SkipToNextMiddleware();
context.Response.Redirect("/Home/Error");

And you probably want to remove the call to context.SkipToNextMiddleware();.

Eilon avatar Feb 16 '17 23:02 Eilon

Guys, I found the root cause, so far it took our lots of time. So tough. We use the .net core 1.1 to develop and deploy the Idsvr4 and Webportal, all the version of packages are >= 1.1.0.
Eventually we had to downgrade these 2 packages to 1.0.1, it has been fixed: "Microsoft.AspNetCore.Authentication.OpenIdConnect": "1.1.0", "Microsoft.AspNetCore.Authentication.Cookies": "1.1.0", "Microsoft.AspNetCore.Diagnostics": "1.1.0", "Microsoft.AspNetCore.Mvc": "1.0.1", "Microsoft.AspNetCore.Mvc.Formatters.Json": "1.1.0", "Microsoft.AspNetCore.Routing": "1.1.0", "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", "Microsoft.AspNetCore.StaticFiles": "1.1.0",

atpyk avatar Feb 20 '17 01:02 atpyk

Many thanks for @Eilon and @PinpointTownes and @Tratcher 's help. :)

atpyk avatar Feb 20 '17 01:02 atpyk

@atpyk ah, yes, mixing versions like that is not supported, so that could definitely be the cause of weird behavior.

Given that this issue appears to be resolved, I'm closing it. Thanks!

Eilon avatar Feb 21 '17 00:02 Eilon

Let me clarify it. Not mixed versions lead to this issue; this issue will happen when use the same version(1.1.0) for all packages. The above solution that is the way to work around.

atpyk avatar Feb 21 '17 05:02 atpyk

@Eilon it looks like @atpyk means that mixing version does resolve this issue. This can't be the correct solution, can it?

henkmollema avatar Feb 21 '17 15:02 henkmollema

Certainly not, but it does hint that the actual problem is in one of the packages you downgraded.

Tratcher avatar Feb 21 '17 17:02 Tratcher

@cesarbs

Tratcher avatar Feb 21 '17 17:02 Tratcher

@Eilon it looks like @atpyk means that mixing version does resolve this issue. This can't be the correct solution, can it?

Oops, I missed that. This is definitely bizarre.

Eilon avatar Feb 21 '17 17:02 Eilon