Skip to content

enable integration with external keycloak clients#1252

Open
GalMunGral wants to merge 3 commits into
mainfrom
external-keycloak-client
Open

enable integration with external keycloak clients#1252
GalMunGral wants to merge 3 commits into
mainfrom
external-keycloak-client

Conversation

@GalMunGral

@GalMunGral GalMunGral commented Nov 18, 2025

Copy link
Copy Markdown
Collaborator

Summary

  • Adds optional redirect_uri query param to the existing GET /auth/token endpoint. If omitted, defaults to Clowder's own settings.auth_redirect_uri.
  • Refactors get_token in utils.py to accept redirect_uri as a keyword argument, using the module-level keycloak_openid instance directly.

Background

IDOT TREC shares the same Keycloak realm and client (clowder2-backend) as Clowder. When a user logs in via IDOT TREC's login button, Keycloak redirects back to the IDOT TREC frontend with an authorization code. IDOT TREC's backend must then call Clowder's /auth/token to exchange that code — not just hit Keycloak directly — because /auth/token upserts the user record into Clowder's MongoDB, which IDOT TREC relies on for group membership and permissions.

Why redirect_uri must be configurable:

Keycloak requires that the redirect_uri passed during the token exchange exactly matches the one used in the original authorization request. Since IDOT TREC's login flow redirects to the IDOT TREC frontend (not Clowder's backend), IDOT TREC must pass its own frontend URL when calling /auth/token. See ncsa/idot-pma@login-oidc: clowder/clowder.py#L305-310.

Used by

ncsa/idot-pma#213 — calls /auth/token passing its own redirect_uri to support the OIDC authorization code flow from an external frontend.

@GalMunGral GalMunGral changed the base branch from update-bitnami-legacy-images to main November 19, 2025 15:11
Restore original /token endpoint unchanged. Add /token/external that
accepts optional client_id, redirect_uri, server_url, realm_name, and
client_secret_key, falling back to Clowder's own settings for any
omitted params.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@GalMunGral GalMunGral marked this pull request as ready for review June 10, 2026 23:42
Drop /token/external — the same Keycloak client supports multiple
redirect URIs, so only redirect_uri needs to vary per caller.
get_token now takes only redirect_uri as an override, using the
module-level keycloak_openid instance directly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@longshuicy longshuicy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The /token endpoint is currently only used by IDOT TREC, but it's designed to support similar auth flows in the future; so if other integrations need the same pattern, we can point them there as well.

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