【发布时间】:2020-09-10 14:17:40
【问题描述】:
我有一个使用 Microsoft.AspNetCore.ApiAuthorization.IdentityServer 包的默认 Microsoft 模板中托管的 Blazor WebAssembly 应用程序。
我需要添加一个单独的客户端以通过客户端凭据请求访问令牌,以使用服务器端应用程序上的 API 控制器端点,但在 Microsoft 网站或 IdentityServer4 文档上找不到任何有关如何注册它们的文档使用微软的实现。
我已尝试在单独的 Config.cs 文件中注册客户端,就像您在典型的 IdentityServer4 项目中所做的那样:
public static IEnumerable<IdentityServer4.Models.Client> Clients =>
new List<IdentityServer4.Models.Client>
{
new IdentityServer4.Models.Client
{
ClientId = "web_id",
ClientSecrets = { new Secret("web_id".ToSha256()) },
AllowedGrantTypes = GrantTypes.ClientCredentials,
AllowedScopes = { "WebAssemblyTest.ServerAPI" }
}
};
启动:
services.AddIdentityServer()
.AddInMemoryClients(Config.Clients)
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
但是,这会在请求令牌时返回客户端未找到错误:
根据 Microsoft Blazor WebAssembly docs,API 资源:“WebAssemblyTest.ServerAPI”是在启动时使用 AddIdentityServerJwt() 注册的,所以我不知道如何让它工作。
【问题讨论】:
标签: c# identityserver4 blazor webassembly blazor-client-side