title: Get IdentityDbContext during ValidateClientAuthentication in my custom OAuthAuthorizationServerProvider
body: <p>I am building a web.api service which uses token for authorization. 
  I've followed the guidelines used by Dominick Baier in his blog <a href="http://leastprivilege.com/2013/11/13/embedding-a-simple-usernamepassword-authorization-server-in-web-api-v2/" rel="nofollow">here</a>.</p>
  
  <p>Today I've updated all the packages for Owin, Entity Framework and ASP.NET web.api and I've found out that lots of things have changed.</p>
  
  <p>I've found a few articles on the web (apparently there no documentation about these topics) and started to convert my web.api service.</p>
  
  <p>This <a href="http://blogs.msdn.com/b/webdev/archive/2014/03/20/test-announcing-rtm-of-asp-net-identity-2-0-0.aspx" rel="nofollow">post</a> about the new ASP.NET Identity 2.0.0 helped me to convert pretty much everything but now I am stuck on a simple stupid matter.</p>
  
  <p>I've managed to create my customer <strong>ApplicationUserManager</strong> and <strong>ApplicationDbContext</strong> as suggested in the blog.</p>
  
  <p>In my <strong>Startup</strong> I've associated my 2 object with the Owin Context:</p>
  
  <pre><code>app.CreatePerOwinContext&lt;ApplicationDatabaseContext&gt;(ApplicationDatabaseContext.Create);
  app.CreatePerOwinContext&lt;ApplicationUserManager&gt;(ApplicationUserManager.Create);
  </code></pre>
  
  <p>I have defined a custom <strong>OAuthAuthorizationServerProvider</strong> cause I want to use <strong>Bearer Authentication</strong>:</p>
  
  <pre><code>var OAuthOptions = new OAuthAuthorizationServerOptions
  {
      AllowInsecureHttp = true,
      TokenEndpointPath = new PathString("/oauth/Token"),
      AccessTokenExpireTimeSpan = TimeSpan.FromHours(8),
      Provider = new MyAuthorizationServerProvider(),
      RefreshTokenProvider = new MyRefreshTokenProvider(DateTime.UtcNow.AddHours(8))
  };
  </code></pre>
  
  <p>In my <strong>MyAuthorizationServerProvider</strong> I have overidden <strong>ValidateClientAuthentication</strong> cause I want to check client credentials.</p>
  
  <p>Everything seems to work fine and I can get my <strong>IAuthenticationManager</strong> from <strong>OwinContext</strong> :</p>
  
  <pre><code>public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
  {
      string clientId = string.Empty;
      string clientSecret = string.Empty;
  
      if (context.TryGetBasicCredentials(out clientId, out clientSecret))
      {
          IAuthenticationManager manager = context.OwinContext.Authentication;
          ...
          ...
      }
  }
  </code></pre>
  
  <p>but I don't seem to be able to get my <strong>ApplicationDbContext</strong>.
  The only way I can achieve this is using the key which I've found going through the variables registered:</p>
  
  <pre><code>var dbContext = context.OwinContext.Get&lt;ApplicationDbContext&gt;("AspNet.Identity.Owin:OwinWebApiSecurity.Services.ApplicationDatabaseContext, OwinWebApiSecurity, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
  </code></pre>
  
  <p>I was wondering if there a simpler way to achieve the same thing.</p>