IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

IdentityServer4 OIDC-Client authorize redirect loop

Open haugan opened this issue 6 years ago • 9 comments

I've built an implementation of IdentityServer4, integrating ASP Identity running ASP.NET Core utilizing the Implicit Flow. (We're changing to a PKCE configuration later on, but whatever.) The application manages user signins across multiple web applications running ASP.NET/AngularJS/OIDC-Client frontends, and ASP.NET/IdentityServer3. backends. When running everything locally on IIS Express, it all works as intended. I can login, logout, silently refresh, life is good. However, after deploying to Azure - I get stuck in an infinite redirect loop attempting to log in and I'm at my wits' end.

The first call to a protected web resource redirects me back to the login service. That's fine. After logging in, I'm sent to the web resource as expected - but, here is where the redirect loop begins.

From the IdentityServer logs on Application Insights I read messages like;

  • Client list checked and origin: "https://webapp.net" is allowed.
  • CorsPolicyService allowed origin: "https://webapp.net"
  • Client configuration validation for client "webclient" succeeded.
  • Token validation success

I can see that the claim types and user info contains espected values, and the GET request to "https://loginservice.net/-well-known/openid-configuration" returns OK (with the expected configurations). I've also verified that the access and id tokens are valid, again containing the expected data.

The OIDC-Client on my web app is configured like this:

vm.userManager = new Oidc.UserManager({
    authority: authorityUrl,
    redirect_uri: windowLocation + '/callback.html',
    silent_redirect_uri: windowLocation + '/silent.html',
    post_logout_redirect_uri: windowLocation + '/index.html',
    client_id: 'appsimplicit',
    scope: 'openid profile role appsmanagement',
    response_type: 'id_token token',
    revokeAccessTokenOnSignout: true,
    automaticSilentRenew: true,
    filterProtocolClaims: true,
    checkSessionInterval: 2000
});

My callback.html looks like this:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <script src="/js/oidc-client.min.js"></script>
    <script>
        new Oidc.UserManager().signinRedirectCallback().then(function(user) {
            window.location = window.location.protocol + "//" + window.location.host + "/";
        }).catch(function(err) {
            console.log(err.message);
        });
    </script>
</body>
</html>

What can I do to fix this? The same behaviour persists across different browsers; Firefox, Chrome, Edge.. I have no idea why it works locally but not deployed to Azure.

haugan avatar Feb 20 '20 12:02 haugan

But, the POST request to "https://loginservice.net/connect/accesstokenvalidation" still fails with a 404.

This endpoint does not exist in IdentityServer...what is this?

leastprivilege avatar Feb 20 '20 13:02 leastprivilege

Sorry, my bad - this is something I got from Azure Application Insights and wrongly assumed to be logging from the new IdentityServer4 implementation. I see now that it's just noise from the old IdentityServer3 implementation still running on another slot. I'll edit my original question. My main headache is ultimately why I get this weird redirect loop when deployed to Azure but not locally. Thanks!

haugan avatar Feb 20 '20 14:02 haugan

Which devices are you having this problem out? In this issue problem solved with configuring automaticSilentRenew. Maybe you've the same problem too.

UmutComlekci avatar Feb 20 '20 14:02 UmutComlekci

Would that explain the initial login redirect loop, though? The situation is the same on all browsers, works locally but not when deployed to Azure. I'm guessing it has something to do with how cookies are handled/read/something, but I'm not smart enough about this stuff to know anything at the moment! In my total desperation, I posted here. :)

haugan avatar Feb 20 '20 14:02 haugan

But, the POST request to "https://loginservice.net/connect/accesstokenvalidation" still fails with a 404.

This endpoint does not exist in IdentityServer...what is this?

Ok, so I found (remembered) we have an API running IdentityServer3.AccessTokenValidation on ASP.NET (not Core). It provides the backend for the web app that's being logged into. Sorry for not being better to gather all the info needed.

haugan avatar Feb 20 '20 15:02 haugan

I had a similar problem with AspNetCore recently. I noticed that the reason for the problem was that I set the cookie domain incorrectly. But I'm never working with Oidc.UserManager, I'm not sure if this is your problem.

UmutComlekci avatar Feb 21 '20 05:02 UmutComlekci

Thanks for the reply, I will see if I can find anything related to this issue and report back.

haugan avatar Feb 21 '20 11:02 haugan

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Questions are community supported only and the authors/maintainers may or may not have time to reply. If you or your company would like commercial support, please see here for more information.

stale[bot] avatar Mar 06 '20 12:03 stale[bot]

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 Apr 15 '20 07:04 lock[bot]