5

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?

tri
  • 191
  • 1
  • 3
  • 9
  • 1
    On top of it, how can I secure my ocelot api gateway so that only the registered users can access the different endpoints, all that using IS4 + AspNetIdentity + EF – tri Jan 17 '19 at 11:47

1 Answers1

3

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

Ron Dobley
  • 143
  • 8