title: ASP.NET Core 2.0 authentication middleware
body: <p>With Core 1.1 followed @blowdart's advice and implemented a custom middleware:</p>
  
  <p><a href="https://stackoverflow.com/a/31465227/29821">https://stackoverflow.com/a/31465227/29821</a></p>
  
  <p>It worked like this:</p>
  
  <ol>
  <li>Middleware ran. Picked up a token from the request headers.</li>
  <li>Verified the token and if valid built an identity (ClaimsIdentity) that contained multiple claims which then it added via HttpContext.User.AddIdentity();</li>
  <li>In ConfigureServices using services.AddAuthorization I've added a policy to require the claim that is provided by the middleware.</li>
  <li>In the controllers/actions I would then use [Authorize(Roles = "some role that the middleware added")]</li>
  </ol>
  
  <p>This somewhat works with 2.0, except that if the token is not valid (step 2 above) and the claim is never added I get "No authenticationScheme was specified, and there was no DefaultChallengeScheme found."</p>
  
  <p>So now I'm reading that auth changed in 2.0:</p>
  
  <p><a href="https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x" rel="noreferrer">https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x</a></p>
  
  <p>What's the right path for me to do the same thing in ASP.NET Core 2.0? I don't see an example to do truly custom authentication.</p>