Skip to content

feat(client/dockerhub): add UserSession expiry helpers - #689

Merged
Benehiko merged 1 commit into
mainfrom
feat/dockerhub-session-expiry
Oct 12, 2026
Merged

Benehiko merged 1 commit into
mainfrom
feat/dockerhub-session-expiry

Conversation

@Benehiko

Copy link
Copy Markdown
Member

Summary

Adds expiry helpers to dockerhub.UserSession so SDK consumers can check whether a Docker Hub access token has expired, or will expire soon (early expiry), before using it.

func (s UserSession) Expired() bool                           // ExpiresWithin(0)
func (s UserSession) ExpiresWithin(leeway time.Duration) bool // expired, or expires within leeway
  • Based on Claims.ExpiresAt compared against time.Now().
  • A positive leeway refreshes early; a negative leeway tolerates clock skew.
  • Fail closed: a session with no (or zero) exp claim is reported as expired, so callers refresh rather than trust an unknown expiry.

Open question

Should a session without claims instead fall back to reading exp from the (unverified) JWT payload in AccessToken? Happy to add that if preferred.

Testing

  • New TestUserSessionExpiry covering valid, within-leeway, expired, negative leeway, missing/zero exp, and the existing wire fixture.
  • README Docker Hub section updated with an example.

SDK consumers need to know whether a Docker Hub access token has expired,
or is about to, before using it. Add Expired and ExpiresWithin methods on
dockerhub.UserSession so callers can check expiry with an early-expiry
window instead of comparing Claims.ExpiresAt themselves.

Sessions without an ExpiresAt claim report as expired.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
@Benehiko
Benehiko force-pushed the feat/dockerhub-session-expiry branch from 9c88969 to ddbb728 Compare October 12, 2026 13:06
@Benehiko
Benehiko marked this pull request as ready for review October 12, 2026 13:09

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assessment: 🟢 APPROVE

@Benehiko
Benehiko enabled auto-merge October 12, 2026 13:12
Comment thread client/dockerhub/dockerhub.go
@Benehiko
Benehiko merged commit 4041259 into main Oct 12, 2026
24 checks passed
@Benehiko
Benehiko deleted the feat/dockerhub-session-expiry branch October 12, 2026 13:16
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