【问题标题】:Identityserver 4 and OcelotIdentityserver 4 和 Ocelot
【发布时间】:2019-06-01 16:34:53
【问题描述】:

我正在尝试将 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:[] is unsupported authentication provider

知道有什么问题吗?我是否需要在我的 IdentityServer 应用中特别设置一些东西?

【问题讨论】:

  • 最重要的是,如何保护我的 ocelot api 网关,以便只有注册用户才能访问不同的端点,所有这些都使用 IS4 + AspNetIdentity + EF

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


【解决方案1】:

您需要添加选项,例如:

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

【讨论】:

    猜你喜欢
    • 2017-12-07
    • 1970-01-01
    • 2017-01-17
    • 2017-07-25
    • 2018-04-25
    • 2018-01-28
    • 2016-09-12
    • 2020-11-04
    • 2018-02-13
    相关资源
    最近更新 更多