8000 Add an on-demand getToken() method by Hakaou · Pull Request #384 · keycloak/keycloak-js · GitHub
[go: up one dir, main page]

Skip to content

Add an on-demand getToken() method - #384

Open
Hakaou wants to merge 1 commit into
keycloak:mainfrom
Hakaou:get-token
Open

Hakaou wants to merge 1 commit into
keycloak:mainfrom
Hakaou:get-token

Conversation

@Hakaou
@Hakaou Hakaou commented Dec 2, 2026
Copy link
Copy Markdown

This adds the on-demand getToken() sketched in #18. My use case is an HTTP interceptor that needs a token for every request.

Decisions:

  • getToken() takes no argument and relies on the default window of updateToken().
  • With the implicit flow it rejects like updateToken() does, even while the access token is still valid.
  • It rejects with Not authenticated when no token is set after the refresh.
  • It is a plain method. An unbound call after destructuring fails.

Not in this PR:

  • The refreshStrategy option from the sketch.
  • A getToken() test with DPoP enabled.

An AI agent wrote the code and the tests under my direction.

Closes #18

@Hakaou
Hakaou marked this pull request as ready for review December 2, 2026 20:29
Callers that need a token right before a request had to call
`updateToken()` and then read the `token` property. `getToken()` does
both and rejects when no token is set afterwards.

Closes keycloak#18

Signed-off-by: Hakaou <akaou.hassan@gmail.com>
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.

Access token is refreshed to late.

1 participant

0