Enabling authentication using Identity

Authentication can be enabled by calling UseIdentity in the pipeline through the Configure method of the Startup class, as follows:

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

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseIdentity();

app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}

The app.UseIdentity method adds cookie-based authentication in the pipeline, which means that when the user is authenticated a cookie will be added in the browser and later used for authentication purposes. The App.UseIdentity method internally uses app.UseCookieAuthentication and sets the cookie named as Identity.Application, whereas, through the AuthenticationOptions, this can be customized. We can also use app.UseCookieAuthentication in case we need to specify all the configurations explicitly.

By now, our application will only display the Hello World! message. In an empty web application project, everything has to be configured manually, whereas with the ASP.NET Core web application project, all the boiler-plate code is added out-of-the-box to register users, authenticate users, and to perform log in and log out operations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.232.187