fix: handle internal hostname without port in Login Flow v2 URL rewriting
Nextcloud may omit default ports in the login_url (e.g. http://app instead of http://app:80). Extract just scheme+hostname from NEXTCLOUD_HOST for the URL replacement check. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
1a51f5bbf5
commit
c2f23a566c
@@ -205,12 +205,17 @@ async def provision_page(request: Request) -> RedirectResponse | HTMLResponse:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Redirect to Nextcloud's Login Flow v2 login page.
|
# Redirect to Nextcloud's Login Flow v2 login page.
|
||||||
# The login_url may use the internal Docker URL (http://app:80/...).
|
# The login_url may use the internal Docker hostname (http://app/...).
|
||||||
# Replace with the public Nextcloud URL for the browser.
|
# Replace with the public Nextcloud URL for the browser.
|
||||||
login_url = init_response.login_url
|
login_url = init_response.login_url
|
||||||
public_issuer = os.getenv("NEXTCLOUD_PUBLIC_ISSUER_URL", "")
|
public_issuer = os.getenv("NEXTCLOUD_PUBLIC_ISSUER_URL", "")
|
||||||
if public_issuer and nextcloud_host and nextcloud_host in login_url:
|
if public_issuer and nextcloud_host:
|
||||||
login_url = login_url.replace(nextcloud_host, public_issuer.rstrip("/"))
|
# Extract just scheme+host from NEXTCLOUD_HOST for matching
|
||||||
|
# (NC may omit default ports, e.g. http://app:80 → http://app)
|
||||||
|
parsed = urlparse(nextcloud_host)
|
||||||
|
internal_origin = f"{parsed.scheme}://{parsed.hostname}"
|
||||||
|
if internal_origin in login_url:
|
||||||
|
login_url = login_url.replace(internal_origin, public_issuer.rstrip("/"))
|
||||||
|
|
||||||
return RedirectResponse(login_url)
|
return RedirectResponse(login_url)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user