Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

net core 2.2 to 3.0 authentication migration AddOpenIdConnect

Currently I'm in upgrading asp net core 2.2 web site to net core 3.0 that uses Identity Server 4 authentication and found issue that stops me to finish this task: In .net core 3.0 there is no AddOpenIdConnect method in OpenIdConnectExtensions (docs are clear about it:

Link

So is there any substitute in .net core 3.0?

Startup.cs that works in net core 2.2

IServiceProvider ConfigureServices(IServiceCollection services)
{    
    services.AddAuthentication(options =>
                    {
                        options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                    })
                    .AddCookie(options =>
                    {
                        options.SlidingExpiration = true;
                        options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
                    })
                    .AddOpenIdConnect("oidc", options =>
                    {
                        options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;

                        options.Authority = "sso url";
                        options.RequireHttpsMetadata = false;

                        options.ClientId = "client_id";
                        options.ClientSecret = "secret";
                        options.ResponseType = $"{OpenIdConnectParameterNames.Code} {OpenIdConnectParameterNames.IdToken}";

                        options.SaveTokens = true;
                        options.GetClaimsFromUserInfoEndpoint = true;                    
                    })
like image 452
Macko Avatar asked Oct 09 '19 11:10

Macko


People also ask

What is new in ASP NET Core 2?

ASP. NET Core ASP.NET Core 2.0 has a new model for authentication and Identity that simplifies configuration by using services. ASP.NET Core 1.x applications that use authentication or Identity can be updated to use the new model as outlined below.

What is a DotNet core authentication?

Dotnet Core is the latest framework from Microsoft that lets you build apps once and deploy to not only Windows, but also Linux and Mac operating systems. It’s quickly gaining popularity, and as a result we’ve seen an increase in people wanting to add authentication to their Dotnet Core apps.

What is EF Core migrations in ASP NET Core?

ASP.NET Core 2.0 Identity uses EF Core to interact with the database storing the authentication data. In order for the newly created app to work, there needs to be a database to store this data. After creating a new app, the fastest way to inspect the schema in a database environment is to create the database using EF Core Migrations.

How do I create an app using DotNet core?

Once you have your Dotnet Core environment installed, open a command prompt and enter the following to create a basic template for our sample app. It will create the new app in its own directory and download any reference libraries that are required.


2 Answers

If you examine the 2.2 -> 3.0 migration document here: https://learn.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio

You will see in the add package references for removed assemblies section (https://learn.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio#add-package-references-for-removed-assemblies) that there is now a nuget package to support this:

https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.OpenIdConnect

like image 120
Josh G Avatar answered Nov 15 '22 00:11

Josh G


For recognizing AddOpenIdConnect, from version 3.0 onwards, you must install package:

Microsoft.AspNetCore.Authentication.OpenIdConnect
like image 36
nima ansari Avatar answered Nov 15 '22 00:11

nima ansari