Problem with starting IdentityServer4

I found out about IdentityServer4 https://identityserver4.readthedocs.io/en/release/quickstarts/0_overview.html , but I seem to have problems with its operation.

After creating the project API section and the corresponding settings:

public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions { Authority = "http://localhost:5000", RequireHttpsMetadata = false, ApiName = "api1" }); app.UseMvc(); } 

I get the following error:

 'IApplicationBuilder' does not contain a definition for 'UseIdentityServerAuthentication' and no extension method 'UseIdentityServerAuthentication' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?) 

Any advice what I'm missing here?

UPDATE 1: I noticed that I cannot reference the namespace, even if the package is installed and present.

those.

 using IdentityServer4.AccessTokenValidation; 

or

 using IdentityServer4; 
+11
source share
6 answers

To provide an update / response, the next version of the IdentityServer4 packages worked fine.

Currently using ID4 2.0 packages.

0
source

Well, I just closed and reopened Visual Studio 2017, and the problem disappeared. Perhaps Visual Studio suffocated the first time the IdentityServer4.AccessTokenValidation package was launched, and reopening the project made him try again, and this time he succeeded.

+20
source

If you are migrating from net core 1.1 to 2.0, you need to migrate the code as described in Identity Server: API migration to ASP.NET Core 2

In setting function

 Before: app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions { Authority = "http://localhost:5000", RequireHttpsMetadata = false, ApiName = "apiApp" }); After: app.UseAuthentication(); 

In ConfigureServices Function

 services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(o => { o.Authority = "http://localhost:5000"; o.Audience = "apiApp"; o.RequireHttpsMetadata = false; }); 
+18
source

You need this package. And use the IdentityServer4.AccessTokenValidation namespace

+10
source

I had the same problem and solved it by running IdentityServer 4 Quickstart Samples , specifically the Javascript Client .

So here is what happened here:

  • Check dependency versions. IdentityServer has problems with .NET Core 2.0 . In my API project, I used version Microsoft.Asp.NetCore.All version 2.0.5 and IdentityServer4.AccessTokenValidation version 2.3.0.

  • Inside Startup.cs, when configuring the add method: app.UseAuthentication (); how it is used as an example .

  • The final step is to add authentication to the ConfigureServices method, as in the example :

     public void ConfigureServices(IServiceCollection services) { services.AddMvcCore() .AddAuthorization() .AddJsonFormatters(); services.AddAuthentication("Bearer") .AddIdentityServerAuthentication(options => { options.Authority = "http://localhost:5000"; options.RequireHttpsMetadata = false; options.ApiName = "api1"; }); } 

And that decided in my case. Hope this works for you too, just let me know how this happens.

Happy coding.

+4
source

You can check the latest documentation on github IdentityServer4 :

It sets authentication parameters in the ConfigureServices method using the services.AddAuthentication method.

Here is the test server they use

-1
source

Source: https://habr.com/ru/post/1265539/


All Articles