5

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

使用时

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

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

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

无法启动 Ocelot,错误为:TestKey,AllowedScopes:[] is unsupported authentication provider

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

4

1 回答 1

3

您需要添加选项,例如:

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

于 2020-02-14T15:57:45.460 回答