Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for multiple backoffice hosts #18302

Merged
merged 2 commits into from
Feb 17, 2025

Conversation

kjac
Copy link
Contributor

@kjac kjac commented Feb 12, 2025

Prerequisites

  • I have added steps to test this contribution in the description below

Description

It is currently not possible to have multiple backoffice hosts. This poses an issue for sites that require multiple hostnames providing access to the backoffice.

Here's a PR to fix 😄

Details

As-is, the first backoffice request "wins"; if I request my.host/umbraco, my.host becomes the allowed backoffice host. If I subsequently request my-other.host/umbraco (provided both hostnames point to the same Umbraco instance), I will be met with a somewhat unfriendly message stating that it is not permitted.

This is all because we need to explicitly configure hosts as allowed for redirection in OpenId Connect (via OpenIddict).

With this PR, backoffice hosts are accumulated over time instead of the current "first in wins" strategy.

To retain backwards compatability, the SecuritySettings.BackOfficeHost takes precedence over any accumulated backoffice hosts (if configured).

Testing this PR

Fire up Umbraco on multiple ports (use launchSettings.json) and verify that you can access Umbraco on all ports.

While you're at it, also verify that the corresponding localtest.me:[port]/umbraco work.

Using a debugger, verify that WebRoutingSettings.UmbracoApplicationUrl is always applied as allowed backoffice host (if configured).

Lastly, verify that SecuritySettings.BackOfficeHost (when configured) takes precedence over both the accumulated hosts and WebRoutingSettings.UmbracoApplicationUrl.

Copy link
Contributor

@AndyButland AndyButland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of small comments made in passing just as I was interested to read through.... I haven't tested.

@nielslyngsoe
Copy link
Member

nielslyngsoe commented Feb 13, 2025

@DanielToft you may want to add your perspectives on this PR.

No requirements for sure, but if you have the time you may want to test if this resolves your case?

If your new to working with the Source Code then read this article. My idea was to build a local version of this branch and verify with a test project, nothing at stake, and verify if this works for you.

https://github.com/umbraco/Umbraco-CMS/blob/contrib/.github/BUILD.md

Thanks in advance

@iOvergaard
Copy link
Contributor

@kjac Without having looked into the code too much, can you outline a bit more how it works regarding authorization if you do not set the BackOfficeHost setting:

  1. Does it allow all URLs that request the backend to authorize?
  2. There are other settings depending on the backoffice host (whether set by request or BackOfficeHost) such as AuthorizeCallbackPathName (where we append either /umbraco or / if working locally) and AuthorizeCallbackLogoutPathName (= /umbraco/logout or /logout). How are they taken into account when autocalculating the backoffice host?

@kjac
Copy link
Contributor Author

kjac commented Feb 14, 2025

@kjac Without having looked into the code too much, can you outline a bit more how it works regarding authorization if you do not set the BackOfficeHost setting:

  1. Does it allow all URLs that request the backend to authorize?

Yep 👍

  1. There are other settings depending on the backoffice host (whether set by request or BackOfficeHost) such as AuthorizeCallbackPathName (where we append either /umbraco or / if working locally) and AuthorizeCallbackLogoutPathName (= /umbraco/logout or /logout). How are they taken into account when autocalculating the backoffice host?

They're always taken into account; if not explicitly defined, the defaults are applied:

image

@iOvergaard
Copy link
Contributor

Thanks, @kjac. With this in place, we can simplify the authorization flow when working locally where we now do not have to set the BackOfficeHost setting. However, we still need to set the other settings, if we do not use the /umbraco subpath:

Before:

"BackOfficeHost": "http://localhost:5173",
"AuthorizeCallbackPathName": "/oauth_complete",
"AuthorizeCallbackLogoutPathName": "/logout",
"AuthorizeCallbackErrorPathName": "/error"

After:

"AuthorizeCallbackPathName": "/oauth_complete",
"AuthorizeCallbackLogoutPathName": "/logout",
"AuthorizeCallbackErrorPathName": "/error"

I wonder what your thoughts are on introducing a new setting that allows us to specify the backoffice subpath (/umbraco) so we only have to set that one when working locally:

"BackOfficePath": "/umbraco"

This is currently being controlled by a constant Constants.System.DefaultUmbracoPath and set through the UmbracoBackOfficePathGenerator. I know it was dynamic before, but then it stopped being dynamic with the introduction of .NET Core. But this would help when hosting the Backoffice on another server, where you potentially might not need/want the /umbraco prefix. I guess that is the ultimate motive at play with this PR.

Copy link
Member

@Zeegaan Zeegaan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works like a charm 🚀

@Zeegaan Zeegaan merged commit 8f9c8cb into v15/dev Feb 17, 2025
27 checks passed
@Zeegaan Zeegaan deleted the v15/feature/multiple-backoffice-hosts branch February 17, 2025 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants