Dependency Injection for ASP.NET Identity 2, OAuth options

Oct 25, 2014 at 5:17 PM
This is a cross post from the Autofac github page, but I am hoping someone here can shed some like on this. I am essentially trying to write end-to-end tests for my WebAPI controllers, but the Identity system introduces things that cannot be injected since they are required in the Startup class. Has anyone worked around this, while still using DI with Identity 2.0?

I am trying to use Autofac in a ASP.net WebApi2 application that uses the ASP.net Identity 2 system. Part of this system uses an extension on the IAppBuilder to register an OAuth provider. I have created a interface for this class, however I cannot get any dependencies to resolve in the startup class- I have tried the following
public static void ConfigureAuth(IAppBuilder app)
{
    //allow cors
    app.UseCors(CorsOptions.AllowAll);

    // Enable the application to use bearer tokens to authenticate users
    var opts = new OAuthBearerAuthenticationOptions
    {
        AuthenticationType = "Bearer",
        AuthenticationMode = AuthenticationMode.Active,
        Provider = new QueryStringOAuthBearerProvider("access_token")
    };
   //service locator ugh, -- only option I see here
var options=  GlobalConfiguration.Configuration.DependencyResolver.
    GetService(typeof (IOAuthAuthorizationServerOptions)) as IOAuthAuthorizationServerOptions;

    app.UseOAuthBearerAuthentication(opts);

    app.UseOAuthAuthorizationServer(options.GetOptions());
}
However, this doesn't work and gets a "No scope with a Tag matching 'AutofacWebRequest' is visible from the scope in which the instance was requested". I tried changing the method to pass the container directly, and using
app.UseOAuthAuthorizationServer(container.Resolve<IOAuthAuthorizationServerOptions>().GetOptions());
This also exhibits the same behavior. Any thoughts on how I can get my OAuth options injected here?