Search code examples
dockerasp.net-web-api.net-corejwtidentityserver4

Authorization Not working with identityserver4 when using docker


I have a .net-core web api app that is configured to use identityserver4.

Everything works fine locally.

One of the web api methods contains [Authorize] attribute that works fine when running locally. But when using "docker" and calling the api method using postman with Authentication Bearer, i get "500 internal server error".

I have this configuration in my web api for CORS.

services.AddCors();

app.UseCors(policy =>
{
    policy.AllowAnyHeader();
    policy.AllowAnyMethod();
    policy.AllowAnyOrigin();
});

Solution

  • i had similar problems with docker, in my case the reason was, that the identityserver was not accessible via the same url in the docker environment as in local (notice that "localhost" in the docker container points to the container itself)