question

mahendranm avatar image
0 Votes"
mahendranm asked Grmacjon-MSFT commented

MVC Client with Identity Server4 authentication falls into infinite Redirect loop

Hi,

I have developed Identity Server Admin which manages Client and Users and IdentityServer4 which manages Authenticating. both application developed in Asp.Net Core 3.1

Identity Sever Admin is multi tenant application as tenant name in host subdomain.

I have deployed in Azure App Service and used custom domain for both Identity Server Admin(MVC Client) and IdentityServer4

Identity Server Admin - https://tenant1.identityserveradmin.com, https://tenant2.identityserveradmin.com, https://allegion.identityserveradmin.com

IdentityServer4 - https://sts.identityserveradmin.com

in the above domains

tenant1 and tenant2 works perfectly as it get authenticate with Identity server4 and save the cookies but allegion domain doesn't save the cookie and goes into redirect loop

below is my cookie configuration in my startup.cs

services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = AuthenticationConsts.OidcAuthenticationScheme;

                 options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                 options.DefaultForbidScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                 options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                 options.DefaultSignOutScheme = CookieAuthenticationDefaults.AuthenticationScheme;
             })
                 .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme,
                     options =>
                     {
                         options.Cookie.Name = adminConfiguration.IdentityAdminCookieName;

                         options.Cookie.SameSite = SameSiteMode.None;
                         options.Cookie.HttpOnly = true;
                         options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
                         options.Events = new CookieAuthenticationEvents
                         {
                             OnSignedIn = context => OnSignedIn(context, adminConfiguration, httpContextAccessor),
                             OnSigningIn = context => OnSigningIn(context, adminConfiguration, httpContextAccessor),
                             OnValidatePrincipal = context => OnValidatePrincipal(context, adminConfiguration, httpContextAccessor)
                         };
                     })

not sure why it's happening weird any help please.

Regards,
Mahendran.

dotnet-csharpdotnet-aspnet-core-mvcazure-webapps-custom-domains
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

mahendranm avatar image
0 Votes"
mahendranm answered Grmacjon-MSFT commented

I fixed the issue myself the Client Secret was mismatching and cookies are not validated so this issue happened. now it got solved

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for sharing the solution that worked for you @mahendranm .

0 Votes 0 ·