323
CHAPTER 8 | Make secure .NET Microservices and Web Applications
To use external
authentication, besides including the authentication middleware as mentioned before,
using the
app.UseAuthentication()
method, you also have to register the external provider in
Program.cs
as shown in the following example:
//...
services.
AddDefaultIdentity
(options => options.
SignIn
.
RequireConfirmedAccount
=
true
)
.
AddEntityFrameworkStores
();
services.
AddAuthentication
()
.
AddMicrosoftAccount
(microsoftOptions =>
{
microsoftOptions.
ClientId
=
builder.
Configuration
[
"Authentication:Microsoft:ClientId"
];
microsoftOptions.
ClientSecret
=
builder.
Configuration
[
"Authentication:Microsoft:ClientSecret"
];
})
.
AddGoogle
(googleOptions => { ... })
.
AddTwitter
(twitterOptions => { ... })
.
AddFacebook
(facebookOptions => { ... });
//...
Popular external authentication providers and their associated NuGet packages are shown in the
following table:
Dostları ilə paylaş: