c# - Identityserver 4 和 Ocelot

标签 c# .net-core identityserver4 api-gateway ocelot

我正在尝试将 Ocelot 与 IS4 一起使用 https://ocelot.readthedocs.io/en/latest/features/authentication.html

使用时

public void ConfigureServices(IServiceCollection services)
{
    var authenticationProviderKey = "TestKey";

    services.AddAuthentication()
        .AddJwtBearer(authenticationProviderKey, x =>
        {
        });
}

并在ocelot.json中使用“TestKey”,启动应用程序时会抛出错误

无法启动 Ocelot,错误为:TestKey、AllowedScopes:[] 是不支持的身份验证提供程序

知道出了什么问题吗?我需要在 IdentityServer 应用程序中进行一些特别的设置吗?

最佳答案

您需要添加选项,例如:

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options =>
    {
        // base-address of your identityserver
        options.Authority = "https://demo.identityserver.io";

        // name of the API resource
        options.Audience = "api1";
    });

更多信息:http://docs.identityserver.io/en/latest/topics/apis.html#

您还需要将 API 资源添加到您的身份服务器:

new ApiResource("api1", "Some API 1")

参见:

http://docs.identityserver.io/en/latest/topics/resources.htmlhttp://docs.identityserver.io/en/latest/reference/api_resource.html#refapiresource

关于c# - Identityserver 4 和 Ocelot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54067154/

相关文章:

c# - Windows 窗体 - 输入按键激活提交按钮?

c# - 最多有 N 个线程按 FIFO 顺序执行的代码部分

msbuild - 无法使用 msbuild 工具构建 .net core 1.1

identityserver4 - WebAPI 项目可以托管多个 API 吗?

.net-core - Identity Server 4 上的关联失败

c# - Tao框架死了吗?

c# - 解决 antlr 中的 token 冲突

c# - System.Text.Json:从 System.IO.Pipelines 反序列化

c# - 消息模板应为编译时间常数

identityserver4 - 在 IdentityServer4 中,谷歌中间件在认证成功后如何处理/signin-google 回调?