Skip to content

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.


- `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
}


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,


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)


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)

@au-ee
Copy link
Contributor

au-ee commented Sep 5, 2025

Hi @frpicard, will you proceed with this PR?
Having it merged would be very helpful for me because I have auth and admin api split which prevents me to use Terraform.

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.

3 participants