Azure App Service Authentication Loop Issue

Jonathan Jasica 20 Reputation points
2025-05-22T03:44:57.07+00:00

My Flask web application running on Azure App Service experiences an authentication loop with Microsoft authentication. After users successfully authenticate with Microsoft OAuth, they are redirected back to the login page instead of being properly authenticated. The server logs show the error message "We found no prior log_in() info from current session" which indicates session persistence problems. Notably, the authentication flow works correctly when running the application locally, suggesting this is an Azure-specific issue.

Technical Details

  1. Environment:
  • Azure App Service
  • Flask web application using Microsoft Identity Platform for authentication
  • Session type: filesystem
  • Python 3.13.2
  1. Symptoms:
  • Authentication flow starts correctly
  • User authenticates with Microsoft successfully
  • Instead of maintaining the authenticated state, users are redirected back to login
  • Debug endpoints show session data is not persisting between requests
  • The ARRAffinitySameSite cookie (Azure's sticky session cookie) is present but doesn't seem to be effectively routing requests
  1. Session Configuration:
  • SESSION_TYPE: "filesystem"
  • SESSION_COOKIE_SECURE: true
  • SESSION_COOKIE_HTTPONLY: true
  • SESSION_COOKIE_SAMESITE: "None"
  • SESSION_COOKIE_DOMAIN: ".itracker.dev"
  • SESSION_FILE_DIR: configured to use a persistent directory in Azure
  1. Authentication Flow:
  • Initial request to /api/auth/sign-in redirects to Microsoft login
  • After Microsoft authentication, user is redirected to our /redirect endpoint
  • At this point, the session from the initial request is lost, causing the "no prior log_in info" error
  • Despite session cookies being present, session data appears empty when requests are processed

Solutions Attempted

  1. Explicitly preserving the ARRAffinitySameSite cookie in responses
  2. Configuring a persistent filesystem session directory
  3. Adding explicit cookie handling middleware

Questions for Microsoft Support

  1. Is there a known issue with session persistence in Azure App Service when using load balancing?
  2. Are there specific recommendations for handling authentication sessions across multiple instances? Is my application running on multiple instances?
  3. Could the ARRAffinitySameSite cookie handling be interfering with our session cookies?
  4. Is there a way to ensure that all requests in an authentication flow are handled by the same server instance?
Azure App Service
Azure App Service

Azure App Service is a service used to create and deploy scalable, mission-critical web apps.


1 answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.