spring-projects / spring-projects/spring-security

Allow configuring a java.time.Clock in OAuth2Authorization.Token

Open
#19,413 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Expected Behavior

It should be possible to configure a custom java.time.Clock on OAuth2Authorization
(via OAuth2Authorization.Builder), so that Token#isExpired(), #isBeforeUse(), and
#isActive() evaluate against the injected Clock instead of the system clock.

Current Behavior

OAuth2Authorization.Token#isExpired() and #isBeforeUse() compare token timestamps
(expiresAt, nbf claim) directly against Instant.now() / the system clock, with no way
to override this externally.

Context

Writing deterministic tests for token expiry, not-yet-valid (nbf), and revocation/refresh
flows currently requires either Thread.sleep(...), constructing tokens with timestamps
computed relative to Instant.now() at test-build time, or mocking static methods — all of
which are brittle or awkward. Injecting a Clock would make these scenarios reproducible
and independent of wall-clock time.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at OAuth2Authorization.Builder and OAuth2Authorization.Token, then trace how isExpired(), isBeforeUse(), and isActive() currently obtain the system time. Define the configured-clock behavior, including the default when no clock is supplied, and verify expiry, nbf, and revocation or refresh scenarios become deterministic without changing existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
authentication, security
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.