IdentityServer / IdentityServer4

OpenID Connect and OAuth 2.0 Framework for ASP.NET Core
https://identityserver.io
Apache License 2.0
9.23k stars 4.02k forks source link

Cannot login if application run in docker container #5410

Closed thanhhn253 closed 2 years ago

thanhhn253 commented 2 years ago

Steps to reproduct:

Please check

Spaeda commented 2 years ago

Hello, I have same issue. It work only in theses cases.

I need to use my docker image on Azure. But, I can't find any way to add a certificate to my docker container.

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build

COPY src ./src

RUN dotnet restore "src/MyIdentityServerHost/MyIdentityServerHost.csproj"
RUN dotnet build "src/MyIdentityServerHost/MyIdentityServerHost.csproj" -c Release --no-restore

FROM build AS publish
RUN dotnet publish "src/MyIdentityServerHost/MyIdentityServerHost.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyIdentityServerHost.dll"]
Spaeda commented 2 years ago

Hello,

@thanhhn253 I finally found a solution to solve my issue. In Startup.cs, I add theses lines:

public void ConfigureServices(IServiceCollection services)
{
  _ = services.Configure<ForwardedHeadersOptions>(options => options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto);
}

public void Configure(IApplicationBuilder app)
{
  _ = app.UseForwardedHeaders();
  _ = app.Use((context, next) =>
  {
    if (context.Request.Headers.TryGetValue("X-Forwarded-Proto", out StringValues proto))
    {
      context.Request.Scheme = proto;
    }
    return next();
  });
}

With this code, authentication work inside a docker container.

thanhhn253 commented 2 years ago

Wow, I can login now. Thank you very much for sharing the solution.

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.