ASPNETCORE 2.0 Identity – Redirect URL signin-* Returns 404

When creating an ASP.NET Core web application using the web app template in VS 2017 preview, a web application with ASP.NET Core 1.1 is scaffolded. Adding external authentication providers following this or this instruction works like a charm. But then, after migrating to ASP.NET Core 2.0, the redirect URL getting the user from the external auth provider back to the web app (i.e. /signin-microsoft, /signin-google, /signin-facebook etc.) stopped working and resulted in a 404.

In ASP.NET Core 1.1, we had to add Identity with the following statement:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.UseIdentity();
}

Which has changed in ASP.NET Core 2.0 to:

public void ConfigureServices(IServiceCollection services)
{
    services.AddIdentity<ApplicationUser, IdentityRole>();
}

Well, it turns out (and is stated in the documents), you now have to explicitly call “UseAuthentication”:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.UseAuthentication();
}

And voila, the redirect URLs work again.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s