C#.NET Core托管Blazor WebAssembly-向{ProjectName} .ServerAPI添加其他客户端访问权限

I have a .NET Core hosted Blazor WebAssembly app from the default Microsoft template using the Microsoft.AspNetCore.ApiAuthorization.IdentityServer package.

我需要添加一个单独的客户端,以通过客户端凭据向服务器端应用程序上的API控制器端点请求访问令牌,但是由于使用Microsoft的实现,因此无法在Microsoft网站或IdentityServer4文档上找到任何有关如何注册它们的文档。

I have tried registering the client in a separate Config.cs file as you would do with a typical IdentityServer4 project:

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>();

但是,这会在请求令牌时返回客户端未找到错误:

enter image description here

Accoring to microsoft Blazor WebAssembly docs, the "WebAssemblyTest.ServerAPI" is registered using the AddIdentityServerJwt() in startup so I have no idea how to get this working.

评论