【发布时间】:2020-01-11 10:40:54
【问题描述】:
我正在努力使用 Net Core 3.0 和 React 进行 Identity Server 4 的基本设置(但这几乎无关紧要)。
我通过dotnet new react -au Individual 生成了新应用,更新了依赖项等,创建的配置基本上是从演示服务器复制的,内容如下:
public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
// JavaScript Client
new Client
{
Enabled = true,
ClientId = "spa",
ClientName = "SPA (Code + PKCE)",
RequireClientSecret = false,
RequireConsent = false,
RedirectUris = { "https://notused" },
PostLogoutRedirectUris = { "https://notused" },
AllowedGrantTypes = GrantTypes.Code,
AllowedScopes = { "openid", "profile", "email", "api" },
AllowOfflineAccess = true,
RefreshTokenUsage = TokenUsage.ReUse
},
};
}
在我的启动中:
services.AddDefaultIdentity<ApplicationUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddIdentityServer(o =>
{
o.UserInteraction.ErrorUrl = "/myErrorsHandler";
o.Events.RaiseErrorEvents = true;
o.Events.RaiseFailureEvents = true;
o.Events.RaiseInformationEvents = true;
o.Events.RaiseSuccessEvents = true;
})
.AddInMemoryApiResources(Config.GetApis())
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>()
.AddInMemoryClients(Config.GetClients()) ;
{"displayMode":null,"uiLocales":null,"error":"unauthorized_client","errorDescription":"Unknown client or client not enabled","requestId":"0HLPL86NBMDRG:00000001","redirectUri":null,"responseMode":null,"clientId":"spa"}
我真的不明白为什么这不起作用。 演示服务器上的相同客户端与 Postman 对话框中的相同客户端可以正常工作。
更新: 我找到了这个文档:https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity-api-authorization?view=aspnetcore-3.0#application-profiles 但我仍然无法让它工作。 它识别客户端,但尽管配置(SPA,IdentityServerSPA)抛出:
{"displayMode":null,"uiLocales":null,"error":"invalid_request","errorDescription":"code challenge required","requestId":"0HLPL8VD22382:00000001","redirectUri":"http://localhost:5000/authentication/login-callback?error=invalid_request&error_description=code%20challenge%20required#_=_","responseMode":"query","clientId":"spa"}
更新 2: 它与配置 JSON 中定义的客户端“工作”,但仅使用 doc 中的预定义模板,但不可能(或没有记录的可能性)禁用 PKCE 以使其工作,例如与邮递员等
【问题讨论】:
-
appsettigs.json中怎么做
-
未知客户端或客户端未启用表示您在请求中提供了错误的 client_id。而code challenge required表示邮递员不支持PKCEI don't use Postman, but google gives me that
-
任何帮助更改它以禁用 appsettings.json 中的 PKCE ` "IdentityServer": { "Key": { "Type": "Development" }, "Clients": { "spa": { “个人资料”:“IdentityServerSPA”,} } }`
-
不确定如何使用配置文件来处理,它们或多或少是硬编码的,但您可以从设置
RequirePkce = false的位置开始使用 this 配置 -
它对代码中定义的客户端根本不起作用:/只是由于某种原因没有加载它
标签: c# .net-core asp.net-identity identityserver4