Identityserver 4和Ocelot

时间:2019-01-07 00:18:00

标签: 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应用中进行特别设置?

1 个答案:

答案 0 :(得分:2)

您需要添加选项,例如:

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资源添加到Identity Server:

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