IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

.NET Core 2.0 support

Open erwinwildenburg opened this issue 9 years ago • 30 comments

  • [x] I read and understood how to enable logging

Issue / Steps to reproduce the problem

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>

Relevant parts of the log file

N/A

erwinwildenburg avatar May 15 '17 18:05 erwinwildenburg

https://github.com/IdentityServer/IdentityServer4/issues/1055

mikeandersun avatar May 15 '17 20:05 mikeandersun

v1 and v2 of aspnet core and not compatible. Run IdentityServer on asp.net core 1.x for the time being.

leastprivilege avatar May 16 '17 06:05 leastprivilege

Dup: https://github.com/IdentityServer/IdentityServer4/issues/1055

brockallen avatar May 25 '17 15:05 brockallen

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.

rhyland avatar Aug 25 '17 17:08 rhyland

Interested here as well. When will 2.0 support be available?

nukec avatar Aug 29 '17 20:08 nukec

Same issue here. Please post the solution once updated

kyl3t avatar Sep 02 '17 13:09 kyl3t

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

erwinwildenburg avatar Sep 02 '17 18:09 erwinwildenburg

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

(E) [email protected]

From: Erwin Wildenburg [mailto:[email protected]] Sent: Saturday, September 2, 2017 12:33 PM To: IdentityServer/IdentityServer4 [email protected] Cc: Hyland Computer Systems, L.L.C. [email protected]; Comment [email protected] 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 .

rhyland avatar Sep 03 '17 16:09 rhyland

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"

vitalbsk avatar Sep 04 '17 03:09 vitalbsk

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 avatar Sep 04 '17 12:09 shanakaip

@shanakaip thanks. But it doesn't work for me.

vitalbsk avatar Sep 04 '17 18:09 vitalbsk

We just released RC1 today. Have a look, and you should be looking at the updates quickstart UI code.

brockallen avatar Sep 04 '17 18:09 brockallen

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"

:(

meds avatar Sep 04 '17 19:09 meds

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.

brockallen avatar Sep 04 '17 19:09 brockallen

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" });

meds avatar Sep 04 '17 19:09 meds

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.

brockallen avatar Sep 04 '17 19:09 brockallen

@meds you can see from my working demo code on how to setup: https://github.com/rizamarhaban/IdentityServer4Demo

rizamarhaban avatar Sep 04 '17 23:09 rizamarhaban

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?

meds avatar Sep 06 '17 05:09 meds

Any update on that?

vitalbsk avatar Sep 10 '17 06:09 vitalbsk

rc1 has been released two weeks ago.

leastprivilege avatar Sep 10 '17 07:09 leastprivilege