Adding authentication to an existing multi tier .Net Core application

services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<PubReviewsContext>()
.AddDefaultTokenProviders();
app.UseAuthentication();

Setting up the Email Sender

services.AddTransient<IEmailSender, Services.EmailSender>(e =>
new EmailSender(Configuration["EmailSettings:host"],
Configuration.GetValue<int>("EmailSettings:port"),
Configuration.GetValue<bool>("EmailSettings:enableSSL"),
Configuration["EmailSettings:UserName"],
Configuration["EmailSettings:Password"]));
var client = new SmtpClient(host, port)                 
{
Credentials = new NetworkCredential(userName,password),
EnableSsl = enableSSL
};
return client.SendMailAsync(
new MailMessage(userName, email, subject,htmlMessage)
{ IsBodyHtml = true }
);
services.ConfigureApplicationCookie(options =>
{
// Cookie settings
options.LoginPath = “/Identity/Account/Login”;
options.AccessDeniedPath = “/Identity/Account/AccessDenied”;
});

Further Reading

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store