title: asp.net core 2.0 authorize with a specific scheme
body: <p>I have an app with a cookie and jwt auth schemes. This is the <code>ConfigureServices</code> code:</p>
  
  <pre class="lang-cs prettyprint-override"><code>var authTokenSettings = configuration.GetSection(nameof(TokenProviderSettings)).Get&lt;TokenProviderSettings&gt;();
  
  services.AddAuthentication(options =&gt;
  {
      options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
      options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
  })
  .AddCookie(authSection.AuthenticationScheme, u =&gt;
  {
      u.Cookie.Name = authSection.AuthCookieName;
      u.LoginPath = new PathString(authSection.LoginPath);
      u.AccessDeniedPath = "/Home/Index";
  })
  .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options =&gt;
  {
      options.RequireHttpsMetadata = false;
      options.TokenValidationParameters = new TokenValidationParameters
      {
          ValidateIssuer = true,
          ValidIssuer = authTokenSettings.Issuer,
          ValidateAudience = true,
          ValidAudience = authTokenSettings.Audience,
          ValidateLifetime = true,
          IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(authTokenSettings.Key)),
          ValidateIssuerSigningKey = true,
      };
  });
  </code></pre>
  
  <p>Now I need to use cookie scheme on one method and jwt on other. I've added appropriate attributes </p>
  
  <pre class="lang-cs prettyprint-override"><code>([Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)])
  </code></pre>
  
  <p>But these attributes are ignored, and the default scheme is used. If I do not specify default scheme, I get this exception:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: No authenticationScheme was
    specified, and there was no DefaultChallengeScheme found.</p>
  </blockquote>
  
  <p>What's wrong with code?</p>