Oauth 2.0 Core3.1 IdentityServer4 WebAPI无法找到/读取访问令牌?

Oauth 2.0 Core3.1 IdentityServer4 WebAPI无法找到/读取访问令牌?,oauth-2.0,identityserver4,openid-connect,webapi,Oauth 2.0,Identityserver4,Openid Connect,Webapi,所以我一直在尝试设置IdentityServer4,使用了PluralSight和公共可用指南中的几个指南 我能够在Core2.1上实现所有功能,但只要我尝试在Core3.1上构建一个IdentityServer4,并使用所有最新版本的框架和与Core2.1示例完全相同的配置,我的webAPI就无法授权客户端应用程序,即使存在令牌 WebAPI是一个.NET4.x项目,使用IdentityServer3.Contrib.AccessTokenValidation包 Core2.1和Core3.1

所以我一直在尝试设置IdentityServer4,使用了PluralSight和公共可用指南中的几个指南

我能够在Core2.1上实现所有功能,但只要我尝试在Core3.1上构建一个IdentityServer4,并使用所有最新版本的框架和与Core2.1示例完全相同的配置,我的webAPI就无法授权客户端应用程序,即使存在令牌

WebAPI是一个.NET4.x项目,使用IdentityServer3.Contrib.AccessTokenValidation包

Core2.1和Core3.1项目的IDP启动配置相同:

services
   .AddIdentityServer()
   .AddDeveloperSigningCredential()
   .AddTestUsers(SeedData.GetUsers())
   .AddInMemoryIdentityResources(SeedData.GetIdentityResources())
   .AddInMemoryApiResources(SeedData.GetApiResources())
   .AddInMemoryClients(SeedData.GetClients());
WebAPI启动配置标识服务器3.Contrib.AccessTokenValidation 适用于Core2.1 IdentityServer 4,但不适用于Core3.1 IdentityServer 4

public void Configuration(IAppBuilder app) {
   app.UseIdentityServerBearerTokenAuthentication(new IdentityServer3.AccessTokenValidation.IdentityServerBearerTokenAuthenticationOptions() {
      Authority = "https://localhost:44314/",
      ClientId = "kpcwebapi",
      RequiredScopes = new[] { "kpcwebapi" },
   });
}
services.AddOpenIdConnect("oidc", options => {
    options.SignInScheme = "Cookies";
    options.Authority = "https://localhost:44314/";
    options.ClientId = "testHybrid";
    options.ResponseType = "code id_token";
    options.Scope.Add("openid"); 
    options.Scope.Add("profile"); 
    options.Scope.Add("kpcwebapi");
    options.SaveTokens = true;
    options.ClientSecret = "secret";
    options.GetClaimsFromUserInfoEndpoint = true;
    options.ClaimActions.Remove("amr");
    options.ClaimActions.DeleteClaim("sid");
    options.ClaimActions.DeleteClaim("idp");
    options.TokenValidationParameters = new TokenValidationParameters {
       NameClaimType = JwtClaimTypes.GivenName,
       RoleClaimType = JwtClaimTypes.Role,
    };    
});
客户端应用程序配置 适用于Core2.1 IdentityServer 4,但不适用于Core3.1 IdentityServer 4

public void Configuration(IAppBuilder app) {
   app.UseIdentityServerBearerTokenAuthentication(new IdentityServer3.AccessTokenValidation.IdentityServerBearerTokenAuthenticationOptions() {
      Authority = "https://localhost:44314/",
      ClientId = "kpcwebapi",
      RequiredScopes = new[] { "kpcwebapi" },
   });
}
services.AddOpenIdConnect("oidc", options => {
    options.SignInScheme = "Cookies";
    options.Authority = "https://localhost:44314/";
    options.ClientId = "testHybrid";
    options.ResponseType = "code id_token";
    options.Scope.Add("openid"); 
    options.Scope.Add("profile"); 
    options.Scope.Add("kpcwebapi");
    options.SaveTokens = true;
    options.ClientSecret = "secret";
    options.GetClaimsFromUserInfoEndpoint = true;
    options.ClaimActions.Remove("amr");
    options.ClaimActions.DeleteClaim("sid");
    options.ClaimActions.DeleteClaim("idp");
    options.TokenValidationParameters = new TokenValidationParameters {
       NameClaimType = JwtClaimTypes.GivenName,
       RoleClaimType = JwtClaimTypes.Role,
    };    
});
我确信配置是正确的,因为一切都在Core2.1上完美工作 我的问题是,我自己找不到,Core3.1 IdentityServer4中是否有任何改变,我的WebAPI不再工作了?我开始认为Core3.1最新版本的IdentityServer4有一个主要的bug/问题。。。因为我们使用的是OpenIDConnect。。。更新IdentityServer时,授权是否仍应有效

有趣的是,当API启动时,每当IDP没有运行时,我都会得到一个异常,如果它正在运行,它会在没有错误/错误的情况下传递语句。 因此,我的API确实建立了与IDP(Core2.1和Core3.1)的连接,但当它是Core3.1 IDP时,从客户端应用程序接收的调用未经过身份验证/授权


<>如果有人知道我做错了什么,我非常感谢分享它,因为我刚花了2个星期的时间试图让它在CIEE3.1上工作。

< p>你的WebAPI,你有没有考虑使用IdditServer 4库代替IdditServer 3? 你可以在这里找到这个例子

是的,我们已经考虑过了,但它不起作用。IdentityServer4是一个.NET核心库,而我们的API是一个.NET 4.x项目,因为它使用EntityFramework6 DbContext