1

I am using ASP.NET Identity with ASP.NET core and I have:

services.AddIdentity<User, Role>();

This works fine when I login. But then I tried this setup:

services
  .AddIdentity<User, Role>(x => {
    x.Cookies = new IdentityCookieOptions {             
      ApplicationCookie = new CookieAuthenticationOptions {
        AccessDeniedPath = new PathString("/signin"),
        AuthenticationScheme = "cookies",
        AutomaticAuthenticate = true,
        AutomaticChallenge = true,
        CookieName = "_ath",
        LoginPath = new PathString("/signin"),
        LogoutPath = new PathString("/signout")
      }
    };
    })
    .AddEntityFrameworkStores<Context, Int32>()
    .AddDefaultTokenProviders();          

With this I get the following error:

No authentication handler is configured to handle the scheme: 
Microsoft.AspNet.Identity.Application    

Note that I have AuthenticationScheme = "cookies", AutomaticAuthenticate = true and AutomaticChallenge = true.

I also have the following in Starttup / Configure method:

  applicationBuilder
    .UseIdentity()
    .UseMvc(routes => { routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}"); })

So I suppose I am using the default order ...

Does anyone knows what am I missing?

Miguel Moura
  • 36,732
  • 85
  • 259
  • 481

2 Answers2

0

I was getting exactly the same error and managed to fix it by adding the default token provider as below:

services.AddIdentity<User, IdentityRole>()
            .AddDefaultTokenProviders();
user3012760
  • 203
  • 2
  • 6
  • Unfortunately that does not help me because I already have that. I updated the code on my question to reflect it ... – Miguel Moura Apr 01 '16 at 15:45
0

Don't set the authenticationScheme directly, or if you do, you need to make sure you also update the corresponding options inside of IdentityOptions to all match.

The error message means that identity is likely still configured to use the default value of 'Microsoft.AspNet.Identity.Application' somewhere, and you changed the cookie middleware to be a different scheme which doesn't match.

Hao Kung
  • 28,040
  • 6
  • 84
  • 93