Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identityserver 4 and Ocelot

I'm trying to use Ocelot with IS4 following https://ocelot.readthedocs.io/en/latest/features/authentication.html

When using

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

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

and use "TestKey" in ocelot.json, it throws an error when starting the application

Unable to start Ocelot, errors are: TestKey,AllowedScopes:[] is unsupported authentication provider

Any idea what's wrong? Do I need set up something in particular in my IdentityServer app?

like image 681
tri Avatar asked Oct 17 '22 08:10

tri


1 Answers

You need to add the options, e.g.:

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";
    });

More info at: http://docs.identityserver.io/en/latest/topics/apis.html#

You will also need to add an API resource to your Identity Server:

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

See:

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

like image 78
Ron Dobley Avatar answered Nov 14 '22 21:11

Ron Dobley