Trying to authenticate a ASP.NET Core 2.0 project with IdentityServer4.
However the authentication part of ASP.NET has undergone some major changes: https://github.com/aspnet/Announcements/issues/232
The only issue so far is:
Reference to type 'AuthenticationOptions' claims it is defined in 'Microsoft.AspNetCore.Authentication', but it could not be found
Startup.cs:
using IdentityServer4.AccessTokenValidation;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Serialization;
using System;
using System.IdentityModel.Tokens.Jwt;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Authentication.Cookies;
namespace API
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Authenticate with IdentityServer4
services.AddAuthentication(options => {
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
});
// Add framework services
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider serviceProvider)
{
// Authenticate with IdentityServer4
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = Configuration.GetValue<string>("Authentication:Authority"),
ApiName = Configuration.GetValue<string>("Authentication:ApiName"),
ApiSecret = Configuration.GetValue<string>("Authentication:ApiSecret"),
SupportedTokens = SupportedTokens.Both,
RequireHttpsMetadata = false
});
app.UseMvc();
}
}
}
Project.csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50;portable-net451+win8</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.2.0" />
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview1-final" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-preview1-final" />
</ItemGroup>
</Project>
N/A
v1 and v2 of aspnet core and not compatible. Run IdentityServer on asp.net core 1.x for the time being.
When will the IdentityServer4 example projects implementing the .NET Core 2.0 SDK be available? Can I sign up on a list to get notified when they do? Thanks.
Interested here as well. When will 2.0 support be available?
Same issue here. Please post the solution once updated
It's available in this repo...
Host project: https://github.com/IdentityServer/IdentityServer4/tree/dev/src/Host
Nuget package: https://preview.nuget.org/packages/IdentityServer4/2.0.0-preview4
Erwin:
Thanks for the update! My company has had great success in implementing our proto-type projects with IdentityServer4 (v1.0) and definitely has its sights set on upgrading to v2.0 just as soon as our “Proof-Of-Concept” (POC) has been demonstrated.
Good work to you and the IdentityServer team for an outstanding, Open Source product that really meets the demands of today’s ever-changing complexities for real-world Internet products. Ones that require Secure Servers to dispense top-notch, quality services and products.
Regards,
Robert Hyland
President & CEO,
Hyland Computer Systems, L.L.C
From: Erwin Wildenburg [mailto:[email protected]]
Sent: Saturday, September 2, 2017 12:33 PM
To: IdentityServer/IdentityServer4 IdentityServer4@noreply.github.com
Cc: Hyland Computer Systems, L.L.C. rob_hyland@sbcglobal.net; Comment comment@noreply.github.com
Subject: Re: [IdentityServer/IdentityServer4] .NET Core 2.0 support (#1173)
It's available in this repo...
Host project: https://github.com/IdentityServer/IdentityServer4/tree/dev/src/Host
Nuget package: https://preview.nuget.org/packages/IdentityServer4/2.0.0-preview4
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/IdentityServer/IdentityServer4/issues/1173#issuecomment-326762091 , or mute the thread https://github.com/notifications/unsubscribe-auth/ADtu5GaxTAXera9qS0yS0KBp6daaHudAks5seZ9UgaJpZM4NbgGf .
Hello everyone,
I still have the same issue:
Reference to type 'AuthenticationOptions' claims it is defined in 'Microsoft.AspNetCore.Authentication', but it could not be found.
here: app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions...
I have:
"IdentityServer4" Version="2.0.0-preview4"
"IdentityServer4.AccessTokenValidation" Version="1.2.1"
Hi vitalbsk
I had the same issue. I removed Microsoft.AspNetCore.All (2.0.0) package and added Microsoft.AspNetCore (2.0.0) & Microsoft.AspNetCore.Mvc (2.0.0), I'm not sure how but it resolved my issue.
@shanakaip thanks. But it doesn't work for me.
We just released RC1 today. Have a look, and you should be looking at the updates quickstart UI code.
We just released RC1 today. Have a look, and you should be looking at the updates quickstart UI code.
I just tried installing the latest IdentityServer4 RC1 package from nuget and I still get the same error,
"error CS7069: Reference to type 'AuthenticationOptions' claims it is defined in 'Microsoft.AspNetCore.Authentication', but it could not be found"
:(
My guess is that you're trying to upgrade an old 1.1 app. You need to gut the csproj and start clean. That's not an IdentityServer problem.
My guess is that you're trying to upgrade an old 1.1 app. You need to gut the csproj and start clean. That's not an IdentityServer problem.
It's actually a fresh Asp.Net Core 2 WebAPI. Just to make sure following on from what you said I created a new WebAPI project for Asp.Net Core 2 and added the same call to UseIdentityServerAuthentication and got the same error:
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = "http://localhost:50151",
RequireHttpsMetadata = false,
ApiName = "scope.readaccess"
});
Ah, I assumed this was in the IdentityServer host. UseIdentityServerAuthentication is our authentication middleware -- it's not yet been ported to ASP.NET Core 2. Use the Jwt Bearer from Microsoft in the meantime.
@meds you can see from my working demo code on how to setup: https://github.com/rizamarhaban/IdentityServer4Demo
Ah, I assumed this was in the IdentityServer host. UseIdentityServerAuthentication is our authentication middleware -- it's not yet been ported to ASP.NET Core 2. Use the Jwt Bearer from Microsoft in the meantime.
Any ETA when this will be supported?
Any update on that?
rc1 has been released two weeks ago.
@leastprivilege I still get the same error even with rc1
Actually from IdentityServer4 Version 2.0.0 onwards (including preview releases and release candidates, the Configurations of AuthenticationServices have been moved to ConfigureServices method instead of Configure method in the Startup class.
Try using services.AddAuthentication(...).AddIdentityServerAuthentication(scheme, options) in ConfigureServices() method instead of the old one in the Configure() method.
I hope you understand this!.
TechnicalGanesh:
I understand the code your are referring to in Startup.cs and I appreciate any other development snippets, pseudo-code or advice that you have to offer on the upgrade to IDSVR2.0
Thanks,
Robert Hyland
President & CEO,
Hyland Computer Systems, L.L.C
(P) 720-616-9965
From: technicalganesh [mailto:[email protected]]
Sent: Monday, September 11, 2017 8:43 AM
To: IdentityServer/IdentityServer4 IdentityServer4@noreply.github.com
Cc: Hyland Computer Systems, L.L.C. rob_hyland@sbcglobal.net; Comment comment@noreply.github.com
Subject: Re: [IdentityServer/IdentityServer4] .NET Core 2.0 support (#1173)
Actually from IdentityServer4 Version 2.0.0 onwards (including preview releases and release candidates, the Configuration of AuthenticationServices have been moved to ConfigureServices method instead of Configure method in the Startup class.
Try using services.AddAuthentication(...).AddIdentityServerAuthentication(scheme, options) in ConfigureServices() method instead of the old one in the Configure() method.
I hope you understand this!.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/IdentityServer/IdentityServer4/issues/1173#issuecomment-328551405 , or mute the thread https://github.com/notifications/unsubscribe-auth/ADtu5BXnHM_JBiwybPhXpPPluVvfO-W6ks5shUb2gaJpZM4NbgGf .
You can find the QuickStart sample here
https://github.com/IdentityServer/IdentityServer4.Samples/tree/release/Quickstarts
Particularly at Hybrid flow authentication for your case!
`app.UseJwtBearerAuthentication(new
Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerOptions
{
Authority = authority,
RequireHttpsMetadata = false,
})`
The Microsoft's Middleware is obsolete now!. What am I supposed to do now?
@waqaskhan540 you can see from my demo here https://github.com/rizamarhaban/IdentityServer4Demo
Are AutomaticAuthenticate and AutomaticChallenge obsolete for IdentityServerAuthenticationOptions?
I changed settings from
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
var identityServerValidationOptions = new IdentityServerAuthenticationOptions
{
Authority = Configuration.GetSection("IdentityServerSettings:Host").Value,
AllowedScopes = new List<string> { "Api" },
ApiSecret = "ApiSecret",
ApiName = "Api",
AutomaticAuthenticate = true,
SupportedTokens = SupportedTokens.Both,
AutomaticChallenge = true,
RequireHttpsMetadata = false
};
app.UseIdentityServerAuthentication(identityServerValidationOptions);
to
services.AddAuthentication()
.AddIdentityServerAuthentication(x =>
{
x.Authority = Configuration.GetSection("IdentityServerSettings:Host").Value;
x.AllowedScopes = new List<string> { "Api" };
x.ApiSecret = "ApiSecret";
x.ApiName = "Api";
x.SupportedTokens = SupportedTokens.Both;
x.RequireHttpsMetadata = false;
});
Addition to @nukec answer: you need for AddIdentityServerAuthentication
install-package IdentityServer4.AccessTokenValidation (ver2.0+)
services.AddAuthentication() .AddIdentityServerAuthentication(x => { x.Authority = Configuration.GetSection("IdentityServerSettings:Host").Value; x.AllowedScopes = new List<string> { "Api" }; x.ApiSecret = "ApiSecret"; x.ApiName = "Api"; x.SupportedTokens = SupportedTokens.Both; x.RequireHttpsMetadata = false; });I had InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found.
so I needed to add this:
services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
.AddIdentityServerAuthentication(x=>
{
x.Authority = "xxx";
x.ApiName = "xxx";
x.RequireHttpsMetadata = false;
});
and in configure method:
app.UseAuthentication();
services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
Adds the default schema
of course You'll need to add package and using IdentityServer4.AccessTokenValidation;
This applies to IdentityServer4.AccessTokenValidation ver 2.1
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Interested here as well. When will 2.0 support be available?