Skip to content

feat: add admin url variable to separate authn and admin api urls #1129

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

frpicard
Copy link
Contributor

No description provided.

…on and admin api calls to the correct URL

Signed-off-by: frpicard <[email protected]>
@frpicard frpicard marked this pull request as ready for review February 20, 2025 10:18
Copy link
Contributor

@sschu sschu left a comment

Choose a reason for hiding this comment

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

@frpicard I finally managed to have a look at your PR. It looks good, I just have some nitpicks to increase readability. If you are fine with my suggested changes, I am happy to merge your PR.

@@ -79,6 +79,7 @@ The following arguments are supported:

- `client_id` - (Required) The `client_id` for the client that was created in the "Keycloak Setup" section. Use the `admin-cli` client if you are using the password grant. Defaults to the environment variable `KEYCLOAK_CLIENT_ID`.
- `url` - (Required) The URL of the Keycloak instance, before `/auth/admin`. Defaults to the environment variable `KEYCLOAK_URL`.
- `admin_url` - (Optional) The admin URL of the Keycloak instance if different from the main URL, before `/auth/admin`. Defaults to the environment variable `KEYCLOAK_ADMIN_URL`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- `admin_url` - (Optional) The admin URL of the Keycloak instance if different from the main URL, before `/auth/admin`. Defaults to the environment variable `KEYCLOAK_ADMIN_URL`.
- `admin_url` - (Optional) The admin URL of the Keycloak instance if different from the base URL, before `/auth/admin`. Defaults to the environment variable `KEYCLOAK_ADMIN_URL`.

Comment on lines +87 to +90
baseUrl := url + basePath
if adminUrl != "" {
baseUrl = adminUrl + basePath
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
baseUrl := url + basePath
if adminUrl != "" {
baseUrl = adminUrl + basePath
}
authUrl := url + basePath
baseUrl := authUrl
if adminUrl != "" {
baseUrl = adminUrl + basePath
}

@@ -26,6 +26,7 @@ import (

type KeycloakClient struct {
baseUrl string
authnUrl string
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
authnUrl string
authUrl string

Comment on lines +92 to +93
baseUrl: baseUrl,
authnUrl: url + basePath,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
baseUrl: baseUrl,
authnUrl: url + basePath,
baseUrl: baseUrl,
authUrl: authUrl,

@@ -112,7 +117,7 @@ func NewKeycloakClient(ctx context.Context, url, basePath, clientId, clientSecre
}

func (keycloakClient *KeycloakClient) login(ctx context.Context) error {
accessTokenUrl := fmt.Sprintf(tokenUrl, keycloakClient.baseUrl, keycloakClient.realm)
accessTokenUrl := fmt.Sprintf(tokenUrl, keycloakClient.authnUrl, keycloakClient.realm)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
accessTokenUrl := fmt.Sprintf(tokenUrl, keycloakClient.authnUrl, keycloakClient.realm)
accessTokenUrl := fmt.Sprintf(tokenUrl, keycloakClient.authUrl, keycloakClient.realm)

@@ -203,7 +208,7 @@ func (keycloakClient *KeycloakClient) login(ctx context.Context) error {
}

func (keycloakClient *KeycloakClient) Refresh(ctx context.Context) error {
refreshTokenUrl := fmt.Sprintf(tokenUrl, keycloakClient.baseUrl, keycloakClient.realm)
refreshTokenUrl := fmt.Sprintf(tokenUrl, keycloakClient.authnUrl, keycloakClient.realm)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
refreshTokenUrl := fmt.Sprintf(tokenUrl, keycloakClient.authnUrl, keycloakClient.realm)
refreshTokenUrl := fmt.Sprintf(tokenUrl, keycloakClient.authUrl, keycloakClient.realm)

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.

2 participants