Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Added IdentityServerOptions.GetPublicHostName #302

Closed
wants to merge 1 commit into from
Closed

Added IdentityServerOptions.GetPublicHostName #302

wants to merge 1 commit into from

Conversation

sam-robinson
Copy link

IdentityServerOptions.GetPublicHostName allows the host name to be configured at Request time, rather than at construction time.

This provides a wider range of configuration options and is especially useful when multiple deployment environments are involved (e.g. local, unit test, test vs production, etc.)

Example:

app.Map("/core", coreApp =>
{
    var factory = Factory.Create();
    var idsrvOptions = new IdentityServerOptions
    {
        // ...
        GetPublicHostName = context => GetSchema() + context.Request.Host.Value,
        // ...
    };

    coreApp.UseIdentityServer(idsrvOptions);
});

// where GetSchema is:
string GetSchema()
{
    return Settings.Default.UseSSL ? "https://" : "http://";
}

IdentityServerOptions.GetPublicHostName allows the host name to be
configured at Request time, rather than at construction time.
@leastprivilege
Copy link
Member

I still don't get the motivation behind that feature - why do you need it? The Katana approach would be to have separate startup classes for different environments.

@sam-robinson
Copy link
Author

The problem I'm having is that I don't know what the PublicHostName is of my machine at startup time. Of course, I'm new to OWIN/Katana so I probably have the workflow wrong...

@leastprivilege
Copy link
Member

Why don't you know that? What's the scenario?

@sam-robinson
Copy link
Author

I am deploying IdSrv on AppHarbor, and I have both a Test and Staging environment. The Staging environment is a staging point for a third setup on Amazon's EC2. And then of course there is the local development environment.

In every case, at startup time I don't have a way of dynamically getting the name of the server. I can set it in the Web.config or via AppHarbor's configuration settings, but I still need to modify those setting wehn pushing to EC2.

The only way I've figured out how to get the server name is at Request time from the OWIN context. I don't have any way to dynamically get it in the OWIN Startup function.

Any suggestions would be greatly appreciated. Thanks!

@sam-robinson
Copy link
Author

So the original reason I went down this road is because if PublicHostName is not set, it defaults to:

"https://" + request.Host.Value

When I'm running in my Test / Staging environment on AH (or locally on Cassini), I don't have an SSL cert.

What if IdentityServerOptions had a Scheme option that defaults to "https", or a UseSSL option that defaults to true?

@leastprivilege
Copy link
Member

OK - we'll consider this.

@leastprivilege
Copy link
Member

Just so that I understand - you deploy to all your environments using exactly the same code base - no configuration differences/transforms etc ?

@sam-robinson
Copy link
Author

We modify web.config settings for external services (e.g. database connections) for a particular environment type. However, we deploy the same environment type to different host machines (e.g. the same Test configuration is run on AH for developer testing and EC2 for QA testing)

@leastprivilege
Copy link
Member

Why did you close?

@sam-robinson
Copy link
Author

Sorry, I should have commented on reasons for closing first.

First, the pull request itself doesn't seem like the correct solution to the problem (specifying HTTP vs HTTPS when PublicHostName is not set)

Second, there is a related feature request here: #341

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants