IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

Support ASP.NET Core 2.0

Open brockallen opened this issue 9 years ago • 84 comments

brockallen avatar Apr 12 '17 14:04 brockallen

@michaelsogos I'll will try to explain it a little more detailed:

Yeah, there is a IdentityServer4 2.0.0-preview2 that works on netcore 2, but you only have the server functionality, that means that, if you try to attach a persistent storage like EntityFrameworkCore or an identity manager like AspNet.Identity even when both Microsoft Packages are updated and working on netcore 2, you need to tell IDS4 to use them and for that you need these 2 packages:

IdentityServer4.AspNetIdentity 1.0.1 IdentityServer4.EntityFramework 1.0.1

And they have dependencies to netcore 1 and nothing more, so that's why you get exceptions, they are not migrated yet.

So here are your choises (At least what I think)

  • You can build your IDS4 and web apis using netcore 1 as the tutorial and docs explain.
  • You can build your IDS4 using netcore 1; Build your web api's or any other resource using netcore 2, and for token validation until the IdentityServer4.AccessTokenValidation package gets migrated, install and configure Microsoft JwtBearer in your resource as suggested by @leastprivilege the way I commented before; If you do so, when we get IdentityServer4 fully supported, you only worry about porting your IDS4 to netcore 2, and minor changes in your web apis.

Good Luck Friend !

DavidNorena avatar Aug 14 '17 13:08 DavidNorena

OK, i get it.

michaelsogos avatar Aug 14 '17 14:08 michaelsogos

Its released its releases! :)

However guys relax there will be support for ASP.NET Core 1 for a full year so no need to immediately upgrade. Not a good idea anyways before being sure its really stable. :)

rh78 avatar Aug 14 '17 21:08 rh78

@rh78 what do you mean ? I don't see full support yet

DavidNorena avatar Aug 15 '17 15:08 DavidNorena

I mean ASP.NET Core 2 has been officially released which means that there can be stable and meaningful works to upgrade IDSrv4 now

rh78 avatar Aug 15 '17 15:08 rh78

Omg ! I was so busy at work, I didnt know that .... you made my day @rh78 Thank you !

DavidNorena avatar Aug 15 '17 16:08 DavidNorena

@DavidNorena Just highlighting yesterday announcements...

https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-net-core-2-0/ https://blogs.msdn.microsoft.com/webdev/2017/08/14/announcing-asp-net-core-2-0/ https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-net-standard-2-0/ https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-entity-framework-core-2-0/

rizamarhaban avatar Aug 15 '17 22:08 rizamarhaban

@DavidNorena , following your suggestion with the ASP.NET Core 2 officially, I have the following error when I try the services.AddJwtBearerAuthentication

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

Is this something that existed on preview and didn't make it to the final version?

DanielSSilva avatar Aug 17 '17 11:08 DanielSSilva

@DanielSSilva , this is from the ASP.NET Core not IdentityServer4 changes. Do this;

      services.AddAuthentication(o =>
        {
            o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
        }).AddJwtBearer(...);

rizamarhaban avatar Aug 17 '17 12:08 rizamarhaban

@DanielSSilva yeah, It was changed, I updated my comment to reflect those changes !

DavidNorena avatar Aug 17 '17 12:08 DavidNorena

Thank you @rizamarhaban, I was aware that it was on ASP.NET and not on IS4, but the sintax changes :)

DanielSSilva avatar Aug 17 '17 13:08 DanielSSilva

asp.net core 2.0 scopes are readonly ? how do we set { "offline_access", "email", "roles" } scopes

empitegayan avatar Aug 21 '17 06:08 empitegayan

@domenkogler Your solution doesn't appear to do the same thing as the original "Quickstart3_ImplicitFlowAuthentication" sample. If I run the MvcClient from that sample, clicking on the "Secure" link redirects me to the IDS and all is well.

When I do as you've instructed, my secure page returns a 401 instead of going through the auth flow.

Can you help?

alexdresko avatar Aug 22 '17 20:08 alexdresko

Anyone have finished work on net core 2.0.?

give the sample please.

julpanid avatar Aug 23 '17 02:08 julpanid

I am trying to port an ASP.NET Core 1.1 client that uses hybrid flow to Core 2.0 (to get better Entity Framework experience). Like empitegayan above, I cannot find a way to specify the Scope (This may not be the full extent of my problems, but it is where I have got to):

.AddOpenIdConnect(options => {
    options.Authority = "https://localhost:5000";
    options.ClientId = "coretest";
    options.ClientSecret = "mysecret";
    options.ResponseType = "code id_token";
    options.Scope = {"openid", "profile", "name", "email", "role"}  // Read-only compilation error
    options.TokenValidationParameters = new TokenValidationParameters {
        NameClaimType = "name",
        RoleClaimType = "role"
     };
});

Any direction on the correct way to reconfigure hybrid flow from 1.1 to 2.0 would be appreciated.

Neilski avatar Aug 23 '17 07:08 Neilski

@Neilski you need to do options.Scope.Add() to add each of them individually, you can't specify them with a constructor anymore.

danjohnso avatar Aug 23 '17 14:08 danjohnso

after configuration you will get this error :

InvalidCastException: Cannot cast Newtonsoft.Json.Linq.JArray to Newtonsoft.Json.Linq.JToken.
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler+<HandleRequestAsync>d__12.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+<Invoke>d__6.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+<Invoke>d__7.MoveNext()

farshidmirza avatar Aug 23 '17 14:08 farshidmirza

Thanks @danjohnso - my small brain completely overlooked that possibility!

Neilski avatar Aug 23 '17 14:08 Neilski

there is a bug with claim name

this is the response of userinfo

{
  "sub": "10",
  "name": [ "user.name", "User Name" ],
  "AspNet.Identity.SecurityStamp": "240dc561-37ff-4eb9-a58a-f760d1b9abaa",
  "role": [ "CSM_User", "dev", "admin", "SuperAdmin", "Admin", "LdapUser", "TranslationAdmin" ],
  "UnitCode": "3120002566",
  "JobTitle": "Kidemli Yazilim Uzmani",
  "JobPhone": "0212 999 9349",
  "given_name": "User",
  "family_name": "Name",
  "birthdate": "03/06/1978",
  "email": "[email protected]",
  "gender": "male"
}

as you see name claim is an array would you please look at this link http://openid.net/specs/openid-connect-core-1_0.html#StandardClaims standard name claim is string and with .net core 2.0 client you cannot use this result

farshidmirza avatar Aug 23 '17 21:08 farshidmirza

@fadihania this is the wrong issue - open a new one with steps to repro.

leastprivilege avatar Aug 24 '17 04:08 leastprivilege