title: Example of using ASP.NET Identity 2.0 UserManagerFactory with UseOAuthBearerTokens method?
body: <p>The ASP.NET Identity 2.0 alpha ships with new middleware to manage getting an instance of the <code>UserManager</code> (<code>app.UseUserManagerFactory</code> to set this up) and getting an instance of the <code>DbContext</code> (<code>app.UseDbContextFactory</code> to set this up). There is an example showing how to get this working with an MVC app, but there is no documentation on how to get this working from the SPA template which uses <code>OAuthBearerTokens</code>, unlike the sample.</p>
  
  <p>I currently am stuck with:</p>
  
  <pre><code>UserManagerFactory = () =&gt; new DerivedUserManager(new CustomUserStore(new CustomDbContext()));
  
  OAuthOptions = new Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerOptions
      {
              TokenEndpointPath = new PathString("/Token"),
              Provider = new MyApp.Web.Api.Providers.ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
              AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
              AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
              AllowInsecureHttp = true
      };
  app.UseOAuthBearerTokens(OAuthOptions);
  </code></pre>
  
  <p>and have no idea how to replace the <code>UserManagerFactory</code> above with calls like these from the 2.0 alpha samples while still working with the <code>OAuthBearerTokens</code> objects used in the SPA template:</p>
  
  <pre><code>        app.UseDbContextFactory(ApplicationDbContext.Create);
  
          // Configure the UserManager
          app.UseUserManagerFactory(new IdentityFactoryOptions&lt;ApplicationUserManager&gt;()
          {
              DataProtectionProvider = app.GetDataProtectionProvider(),
              Provider = new IdentityFactoryProvider&lt;ApplicationUserManager&gt;()
              {
                  OnCreate = ApplicationUserManager.Create
              }
          });
  </code></pre>
  
  <p>Thanks...
  -Ben</p>