Reputation: 8414
I am learning about the IdentityServer4 https://identityserver4.readthedocs.io/en/release/quickstarts/0_overview.html but seem to be having issues getting it working.
After creating the API section of the project and configured accordingly:
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 am missing here?
EDIT 1: I've noticed i cannot reference the namespace either even tho the package is installed and present.
i.e.
using IdentityServer4.AccessTokenValidation;
or
using IdentityServer4;
Upvotes: 15
Views: 16746
Reputation: 489
If you migrate from net core 1.1 to 2.0, you need to migrate your code as described in Identity Server: API Migration to ASP.NET Core 2
In the Configure function
Before:
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = "http://localhost:5000",
RequireHttpsMetadata = false,
ApiName = "apiApp"
});
After:
app.UseAuthentication();
In the 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;
});
Upvotes: 23
Reputation: 9508
I had the same issue and I solved by following IdentityServer 4 Quickstart Samples, in particular the Javascript Client sample.
So, this is what it worked here:
Check dependencies versions. There are issues reported for IdentityServer running with .NET Core 2.0. In my API project I used Microsoft.Asp.NetCore.All version 2.0.5 and IdentityServer4.AccessTokenValidation version 2.3.0.
Inside Startup.cs, at Configure method add: app.UseAuthentication(); as it is used in the example.
The last step is to add authentication to ConfigureServices method as it is 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 solved in my case. Hopefully it works for you too, just let me know how it goes.
Happy coding.
Upvotes: 6
Reputation: 1
You can check the latest documentation at github IdentityServer4:
It sets the authentication options in the ConfigureServices
method using the services.AddAuthentication
method.
Here is the test server code they are using
Upvotes: -1
Reputation: 8414
Just to provide update/answer, the subsequent version of IdentityServer4 packages worked fine.
Currently using ID4 2.0 packages.
Upvotes: 0
Reputation: 22063
Well, I just closed and reopened Visual Studio 2017, and the problem went away. Perhaps Visual Studio choked on pulling down the IdentityServer4.AccessTokenValidation package the first time, and reopening the project caused it to try again and this time it succeeded.
Upvotes: 23