Skip to content

fix(push): pre-refresh access token before invoking Gradle plugin#18

Merged
hbrombeer merged 1 commit intomainfrom
fix/push-pre-refresh-token
Apr 29, 2026
Merged

fix(push): pre-refresh access token before invoking Gradle plugin#18
hbrombeer merged 1 commit intomainfrom
fix/push-pre-refresh-token

Conversation

@hbrombeer
Copy link
Copy Markdown
Member

Summary

`grounds push push` was forcing users to re-run `grounds login` between every push attempt that took longer than ~5 minutes to set up. Reported by @lusu007: "läuft gefühlt alle 5min ab".

Root cause: the Gradle plugin reads `credentials.json` directly via `CredentialResolver` and rejects expired access tokens — but never calls the OIDC refresh endpoint itself. Keycloak's default access-token lifetime is ~5 min. The CLI's auto-refresh logic in `FileTokenSource.Token()` was only invoked by CLI-internal API calls (`grounds cluster up`, etc.), never by the wrapped Gradle task.

Fix

Wire `FileTokenSource.Token()` in front of the `gradle.Run()` call. It:

  1. Reads credentials.json
  2. If access-token is expired (or expiring within 30s), exchanges the refresh-token for a fresh one
  3. Persists the new tokens back to credentials.json
  4. Then the Gradle plugin reads the now-fresh file

When `GROUNDS_TOKEN` is set, skip the pre-refresh — the plugin uses the env var directly via `Credentials.FromEnv` and never touches the file.

Test plan

  • `go build ./...` clean
  • `go vet ./...` clean
  • Existing push + auth tests pass
  • Lukas confirms `grounds push push` works after a token has expired (next 0.1.7 release)

Companion to #16 (credentials.json version field).

🤖 Generated with Claude Code

The Gradle plugin reads credentials.json directly via CredentialResolver
and rejects expired access tokens — without ever calling the OIDC
refresh endpoint. Keycloak's default access-token lifetime is ~5min,
so users had to re-run 'grounds login' between every push attempt
that took longer than that to set up.

Wire the CLI's existing FileTokenSource.Token() in front of the
gradle.Run() call: it transparently refreshes the access token (using
the still-valid refresh token) and persists the new credentials to
disk before Gradle reads the file.

Skip the pre-refresh when GROUNDS_TOKEN is set — the plugin uses the
env var directly via Credentials.FromEnv, bypassing the file.

Reported by lusu007: 'läuft gefühlt alle 5min ab'.
@hbrombeer hbrombeer merged commit 109da76 into main Apr 29, 2026
5 checks passed
@hbrombeer hbrombeer deleted the fix/push-pre-refresh-token branch April 29, 2026 17:00
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.

1 participant