title: Dissecting ASP.NET MVC Identity for OAuth Bearer Authentication
body: <p>I'm learning how to put the Asp.Net MVC Identity 2.0 to work.</p>
  
  <p>I have this code that works for OAuth Bearer</p>
  
  <pre><code>    [HttpGet]
      [ActionName("Authenticate")]
      [AllowAnonymous]
      public String Authenticate(string user, string password)
      {
          if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(password))
          {
              return "Failed";
          }
  
          var userIdentity = UserManager.FindAsync(user, password).Result;
          if (userIdentity != null)
          {
              if (User.Identity.IsAuthenticated)
              {
                  return "Already authenticated!";
              }
  
              var identity = new ClaimsIdentity(Startup.OAuthBearerOptions.AuthenticationType);
              identity.AddClaim(new Claim(ClaimTypes.Name, user));
              identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userIdentity.Id));
  
              AuthenticationTicket ticket = new AuthenticationTicket(identity, new AuthenticationProperties());
              var currentUtc = new SystemClock().UtcNow;
              ticket.Properties.IssuedUtc = currentUtc;
              ticket.Properties.ExpiresUtc = currentUtc.Add(TimeSpan.FromMinutes(1));
  
              string AccessToken = Startup.OAuthBearerOptions.AccessTokenFormat.Protect(ticket);
              return AccessToken;
          }
          return "Failed in the end";
      }
  </code></pre>
  
  <p>Here is the code for Startup.Auth.cs</p>
  
  <pre><code>    //This will used the HTTP header Authorization: "Bearer 1234123412341234asdfasdfasdfasdf"
      OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
      app.UseOAuthBearerAuthentication(OAuthBearerOptions);
  </code></pre>
  
  <p>I have looked at the source code for ClaimsIdentity and AuthenticationTicket and I don't see how the ticket is registered for the identity.</p>
  
  <p>My question is how did this ticket get registered with the Owin pipeline?</p>
  
  <p>My aim is to revoke this ticket if possible.</p>
  
  <p>Thanks in advance.</p>