title: OpenIdConnectAuthenticationHandler: message.State is null or empty. when connecting to Azure Active Directory
body: <p>I'm trying to connect to Azure Active Directory with my application, but I'm getting this error:
  An unhandled exception occurred while processing the request.</p>
  
  <blockquote>
    <p>Exception: OpenIdConnectAuthenticationHandler: message.State is null
    or empty. Unknown location</p>
    
    <p>AggregateException: Unhandled remote failure.
    Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.d__5.MoveNext()</p>
  </blockquote>
  
  <p>My appsettings.json file looks like this:</p>
  
  <pre><code>"AzureAd": {
      "ClientId": "&lt;Application ID value from Azure Portal&gt;",
      "AadInstance": "https://login.microsoftonline.com/{0}",
      "TenantId": "&lt;tenant&gt;.onmicrosoft.com",
      "AuthCallback": "/"
    }
  </code></pre>
  
  <p>and in Startup.cs</p>
  
  <pre><code>  app.UseCookieAuthentication();
  
    app.UseIdentity();
    app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
    {
         ClientId = Configuration["AzureAd:ClientId"],
         Authority = string.Format(Configuration["AzureAd:AadInstance"], Configuration["AzureAd:TenantId"]),
         CallbackPath = Configuration["AzureAd:AuthCallback"]
    });
  </code></pre>
  
  <p>I've enabled ssl in my project, and added the url that Visual Studio gives me as the reply URL.</p>
  
  <p>Before, when I had an incorrect URL configured, it led me to the Microsoft login site that said that the URL didn't match any registered ones, so I know it at least got that far.</p>
  
  <p>I should also say that I was following <a href="https://joonasw.net/view/asp-net-core-1-azure-ad-authentication" rel="nofollow noreferrer">this post</a>, but using the new portal. I don't have access to the classic portal.</p>
  
  <p>How can I resolve this error?</p>
  
  <p>Thank you for any help.</p>