title: How to validate Azure B2C access token using Authorization in .Core application
body: <p>I'm able to successfully validate an access token issued by Azure AD B2C inside the controller using this code:</p>
  <pre><code>string discoveryEndpoint = &quot;https://&lt;tenant&gt;.b2clogin.com/&lt;tenant&gt;.onmicrosoft.com/&lt;policyId&gt;/v2.0/.well-known/openid-configuration&quot;;
  ConfigurationManager&lt;OpenIdConnectConfiguration&gt; configManager = new(discoveryEndpoint, new OpenIdConnectConfigurationRetriever());
  OpenIdConnectConfiguration openIdconfig = configManager.GetConfigurationAsync().Result;
  TokenValidationParameters validationParameters = new()
  {
      ValidateAudience = true,
      ValidAudience = &lt;ClientId&gt;,
      ValidateIssuer = true,
      ValidIssuer = openIdconfig.Issuer,
      IssuerSigningKeys = openIdconfig.SigningKeys,
      ValidateLifetime = true
  };
  JwtSecurityTokenHandler tokenHandler = new();
  tokenHandler.ValidateToken(accessToken, validationParameters, out SecurityToken validatedToken);
  </code></pre>
  <p>But can't make it work setting up authorization in Startup.cs like this</p>
  <pre><code>services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
     .AddJwtBearer(cfg =&gt;
     {
         &lt;...the same code as above to get issuer and signing keys...&gt;
         cfg.TokenValidationParameters = new()
         {
            ValidateAudience = true,
            ValidAudience = &lt;ClientId&gt;,
            ValidateIssuer = true,
            ValidIssuer = openIdconfig.Issuer,
            IssuerSigningKeys = openIdconfig.SigningKeys,
            ValidateLifetime = true
         };
     });
  &lt;...&gt;
  public void Configure(IApplicationBuilder appBuilder)
  {
     &lt;...&gt;
     appBuilder.UseRouting();
     appBuilder.UseAuthorization();
     &lt;...&gt;
  }
  </code></pre>
  <p>and using [Authorize] attribute in my controller method. In this case I get 401 response. What am I doing wrong here?</p>