title: Azure Web App + Node.js + Azure AD = Error 431
body: <p>I created a Node.js based web application, running in an Azure Web App, that I wanted to put behind an Azure Active Directory authentication. After activating "App Service Authentication", the login process works normally, however upon returning to my app, it just returns a HTTP 431 "Request Header Fields Too Large".</p>
  
  <p>To validate it's not my app, I checked the Azure web app sample for Node.js and even this returns a 431 when activating AAD.</p>
  
  <p><strong>Steps to reproduce:</strong></p>
  
  <ul>
  <li>Create new Azure resource -> Web App
  
  <ul>
  <li>Select any Node based runtime stack, for example Node 12 LTS</li>
  <li>Select any OS</li>
  <li>Create the web app and wait for deployment to finish</li>
  </ul></li>
  <li>Create a simple web app
  
  <ul>
  <li>Example: <a href="https://github.com/Azure-Samples/app-service-web-nodejs-get-started" rel="noreferrer">https://github.com/Azure-Samples/app-service-web-nodejs-get-started</a></li>
  <li>Deploy on the web service</li>
  <li>Result so far: App works.</li>
  </ul></li>
  <li>In the web app settings, go to "Authentication / Authorization"
  
  <ul>
  <li>Turn "App Service Authentication" to "On"</li>
  <li>Select Azure Active Directory</li>
  <li>Select Express Management Mode and create a new Azure AD App in the process</li>
  <li>As "Action to take when request is not authenticated" select "Log in with Azure AD"</li>
  <li>Confirm</li>
  </ul></li>
  </ul>
  
  <p>Result: When opening the web app URL with a browser, it will show the log in process, following the process everything seems to work fine and the AAD returns to the application, however at that point it returns a HTTP 431.</p>
  
  <p><strong>Further tests:</strong></p>
  
  <ul>
  <li>Deactivate the authentication and everything works fine again</li>
  <li>Upload a simple .html file instead of a Node app works fine with authentication enabled</li>
  <li>Tested with restify and http</li>
  </ul>
  
  <p>Any ideas? Am I missing something?</p>