Identityserver4: public origin is not found in options in v4.x

Created on 7 Jul 2020  路  14Comments  路  Source: IdentityServer/IdentityServer4

var identityBuilder = collection.AddIdentityServer(option =>
            {
                //option.UserInteraction.ErrorUrl = "";
                var publicOrigin = config["public_origin"];
                if (publicOrigin?.Length > 0)
                {
                    option.PublicOrigin= publicOrigin;//complie error
                }
            });
question

Most helpful comment

We removed it. Use the forwarded headers instead.

@leastprivilege,

Why did you removed it? Is there another way to modify origin? It did currently break our server. So I had to downgrade it to build project. I know I can use forwarded headers. But it doesn't works. The only way to fix that issue is using PublicOrigin :(

All 14 comments

We removed it. Use the forwarded headers instead.

@hiwjcn To use forwarded headers:
In the Startup.ConfigureServices :

services.Configure<ForwardedHeadersOptions>(options =>
{
    options.ForwardedHeaders =
        ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost;
    options.KnownNetworks.Clear();
    options.KnownProxies.Clear();
});

In the Startup.Configure :

app.UseForwardedHeaders();

Then you can pass the headers X-Forwarded-Proto=<https or http> and X-Forwarded-host=<your_host> in the request.

thanks, and pls update to the docs in the break change section :)

We removed it. Use the forwarded headers instead.

@leastprivilege,

Why did you removed it? Is there another way to modify origin? It did currently break our server. So I had to downgrade it to build project. I know I can use forwarded headers. But it doesn't works. The only way to fix that issue is using PublicOrigin :(

Just FYI this solves Issue 46 and Issue 324 as well for anyone who winds up on one of those pages first.

@leastprivilege Does the fix with forwarded headers also corrects the endpoints in the Discovery Endpoint output document, so that they are relative to custom path?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Questions are community supported only and the authors/maintainers may or may not have time to reply. If you or your company would like commercial support, please see here for more information.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Questions are community supported only and the authors/maintainers may or may not have time to reply. If you or your company would like commercial support, please see here for more information.

Here's temporary fix 馃槄

Just add a middleware before identity server to modify host and protocol properties of HttpContext.Request. It worked for me =)

I configured in Startup.ConfigureServices:

services.Configure<ForwardedHeadersOptions>(options =>
                                                        {
                                                            options.ForwardedHeaders = ForwardedHeaders.XForwardedFor |
                                                                                       ForwardedHeaders.XForwardedProto |
                                                                                       ForwardedHeaders.XForwardedHost;
                                                            options.KnownNetworks.Clear();
                                                            options.KnownProxies.Clear();
                                                        });

and in Startup.Configure:

app.UseForwardedHeaders()
               .UseHttpsRedirection()
               .UseCors()
               .UseStaticFiles()
               .UseRouting()
               .UseIdentityServer();

Still getting HTTP URLs in Discovery Document instead of HTTPS as expected.
I'd prefer to get back Public Origin setting. This is very annoying to solve when before we could solve it on our own without so much dependency from the network team.

What other alternative do I have right now if this Startup configurations don't work?

@CesarD This is how I solved that:

```c#
app.Use((context, next) =>
{
context.Request.Protocol = "https";
context.Request.Host = new HostString("my-domain.com:12345");
// Only if you need it.
context.Request.PathBase = new PathString("/api/auth");

return next();

});
```

Thanks a lot @M0ns1gn0r !! :)

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.

Was this page helpful?
0 / 5 - 0 ratings