Skip to content

fix: normalize Keycloak base URL to preserve realm path - #619

Open
aryarathoree wants to merge 1 commit into
microcks:masterfrom
aryarathoree:fix/keycloak-url-trailing-slash
Open

aryarathoree wants to merge 1 commit into
microcks:masterfrom
aryarathoree:fix/keycloak-url-trailing-slash

Conversation

@aryarathoree

@aryarathoree aryarathoree commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #606

In NewKeycloakClientWithContext, normalizes kc.BaseURL so that its path always ends with a trailing slash (/).

Under RFC 3986 relative URL resolution, resolving relative endpoints like protocol/openid-connect/token or .well-known/openid-configuration against a base path lacking a trailing slash strips the final path segment (e.g. /realms/microcks becomes /realms/protocol/openid-connect/token). This change ensures standard Keycloak realm URLs passed by direct callers preserve their realm path when constructing requests.

Changes

  1. Added trailing slash normalization on u.Path and u.RawPath in NewKeycloakClientWithContext (keycloak_client.go).
  2. Added unit tests in keycloak_client_test.go:
    • TestNewKeycloakClient_NormalizesTrailingSlash: tests various realm URL variations (with slash, without slash, root, nested subpath).
    • TestKeycloakClient_EndpointsPreserveRealmPath: verifies that ConnectAndGetToken, GetOIDCConfig, and ConnectAndGetTokenAndRefreshToken preserve the realm path when resolving endpoints against a realm URL that lacks a trailing slash.

@Harsh4902

Copy link
Copy Markdown
Member

@aryarathoree Please check the DCO onec. One of the commits dosen't have sign-off.

Ensure realmURL path ends with a trailing slash in NewKeycloakClientWithContext so that net/url ResolveReference does not strip the realm path segment when requesting tokens or OIDC configuration.

Fixes microcks#606

Signed-off-by: Arya Rathore <[email protected]>
@aryarathoree
aryarathoree force-pushed the fix/keycloak-url-trailing-slash branch from 62ff6bd to f7f8300 Compare November 12, 2026 17:04
@aryarathoree

Copy link
Copy Markdown
Contributor Author

@Harsh4902 I've signed off the commit. All checks are passing now.

This branch was successfully deployed

1 active deployment
Build — f7f8300f Deployed Nov 12, 2026 by aryarathoree via build-verify-package #885
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KeycloakClient strips realm path when realm URL lacks trailing slash

2 participants