title: Azure AD Not Authenticating in .NET Core 3.1
body: <p>I'm trying to get Azure AD working in an existing application. I've followed the instructions and looked at the sample code from Microsoft's site (<a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-v2-aspnet-core-webapp" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-v2-aspnet-core-webapp</a>) with no luck. The sample code is using .NET Core 2.1. I can get it to work with .NET Core 2.1 but 3.1 is throwing a fit for a couple reasons.</p>
  
  <ol>
  <li>Compared to sample code one needs to set the EnableEndpointRouting to false.</li>
  <li>Compared to sample code I tried removing the set compatibilityversion on AddMvc and also tried using it as being set to 3.0.</li>
  </ol>
  
  <p>When I run it in .NET Core 3.1 all it does is load the page and never calls out/perform the authentication and is behaving as if there is not Authorize tag on the controller.</p>
  
  <p>I have an Authorize tag on the class level in controller.</p>
  
  <p>Startup.cs:</p>
  
  <pre><code>...
              services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
              {
                  options.CheckConsentNeeded = context =&gt; true;
                  options.MinimumSameSitePolicy = SameSiteMode.None;
              });
  
              services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
                  .AddAzureAD(options =&gt; Configuration.Bind("AzureAd", options));
  
              services.Configure&lt;OpenIdConnectOptions&gt;(AzureADDefaults.OpenIdScheme, options =&gt;
              {
                  options.Authority = options.Authority + "/v2.0/";
                  options.TokenValidationParameters.ValidateIssuer = false;
              });
  
              services.AddMvc(options =&gt;
              {
                  var policy = new AuthorizationPolicyBuilder()
                      .RequireAuthenticatedUser()
                      .Build();
                  options.Filters.Add(new AuthorizeFilter(policy));
                  options.EnableEndpointRouting = false;
              });
  </code></pre>
  
  <p>Then down below in the Configure function:</p>
  
  <pre><code>...
  app.UseHttpsRedirection();
              app.UseStaticFiles();
              app.UseCookiePolicy();
  
              app.UseAuthentication();
  
              app.UseMvc(routes =&gt;
              {
                  routes.MapRoute(
                      name: "default",
                      template: "{controller=Home}/{action=Index}/{id?}");
              });
  </code></pre>
  
  <p>Then in my appsettings.json I have:</p>
  
  <pre><code>{
    "AzureAd": {
      "Instance": "https://login.microsoftonline.com/",
      "Domain": "domain.onmicrosoft.com",
      "TenantId": "guid",
      "ClientId": "guid",
      "CallbackPath": "/signin-oidc"
    },
  ...
  </code></pre>
  
  <p>My question is why is it treating the requests as if their is no authentication? I have also tried using the UseAuthorization below the UseAuthentication.</p>
  
  <p>Thanks!</p>