Authentication enters into infinite loop #258
Replies: 4 comments 2 replies
-
|
I would suggest adding some breakpoints in the various There is one thing I would to, and that's a small bugfix in the public async Task RenewAsync(string key, AuthenticationTicket ticket)
{
ArgumentNullException.ThrowIfNull(ticket);
try
{
var options = new DistributedCacheEntryOptions();
var expiresUtc = ticket.Properties.ExpiresUtc;
if (expiresUtc.HasValue)
{
options.SetAbsoluteExpiration(expiresUtc.Value);
}
if (ticket.Properties.AllowRefresh ?? false)
{
options.SetSlidingExpiration(TimeSpan.FromMinutes(60));
}
// Added await here, because if something would've failed here, you'd never fall into the catch block in this method.
return await cache.SetAsync(key, ticketSerializer.Serialize(ticket), options);
}
catch (Exception ex)
{
logger.LogError(ex);
}
} |
Beta Was this translation helpful? Give feedback.
-
|
I catched that missing The methods What other code is executed between these 2 methods where I can debug/log? |
Beta Was this translation helpful? Give feedback.
-
|
This is my As you can see, I'm logging the events. However, the log shows the following: 2025-07-04 17:29:52.834 [DBG] [CookieEvents.SigningIn] Signing in with cookie authentication. Nothing else is being logged between these 2 events. |
Beta Was this translation helpful? Give feedback.
-
|
I am setting a cookie path for all cookies (authentication, culture, consent). I noticed that when this infinite redirect happens there is an extra set of cookies but the path is just '/'. This is the problem because as soon as I delete these cookies, leave those with the path and refresh the page, everything works as expected. So which middleware can be recreating these set of cookies without the path? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a Blazor server-side app set up and initially authentication will work as expected. I am also using sql server distributed cache to store authentication tickets (ITicketStore) and user tokens (IUserTokenStore)
Setting up of services is:
This is my implementation of the
ITicketStore:I baed my code in the v3.3.0 sample and everything works fine until after some hours of inactivity (maybe 24hours). When the user starts the app again it enters into an infinite redirect loop between the auth provider and the login callback. The cookie events
SigningInandSignedInare called ad infinitum. Also, theRenewAsyncis called within this infinite loop and a new cache entry is added every time.The only way to stop the loop by the user is to delete the cookies. Once done, the user is redirected to the login page as normal and flow proceeds as expected.
From what I can see, cookie/authentication configuration looks good.
Could the expiration settings of the different tickets/tokens/cache entries be causing this issue?
Beta Was this translation helpful? Give feedback.
All reactions