Skip to content

fix(TokenClient): respect client_authentication when revoking tokens - #2484

Open
yuminn-k wants to merge 1 commit into
authts:mainfrom
yuminn-k:fix/revoke-client-authentication
Open

yuminn-k wants to merge 1 commit into
authts:mainfrom
yuminn-k:fix/revoke-client-authentication

Conversation

@yuminn-k

Copy link
Copy Markdown

Closes #752

TokenClient.revoke() always put client_secret in the request body and never passed basicAuth to postForm, so it ignored the client_authentication setting that the code, credentials and refresh-token requests honour.

With this change, the client_authentication switch that was repeated in exchangeCode, exchangeCredentials and exchangeRefreshToken moves into one private helper (_applyClientAuthentication), as suggested in the issue. revoke() now uses it too:

  • client_secret_basic: Authorization: Basic ... header, no client_secret in the body
  • client_secret_post: client_id and client_secret in the body (same as before)
  • client_secret_jwt: client_assertion in the body instead of the raw client_secret (before, the raw secret was sent in the body with this setting)

The "A client_secret is required" check is also shared via _assertClientSecret, so revoke() now throws it for client_secret_basic/client_secret_jwt without a secret, like the other requests. With the default client_secret_post nothing changes.

Tests: three cases added under describe("revoke") (basic, post, jwt). On main the basic and jwt cases fail; the post case passes on both and guards the unchanged behaviour. Full suite and lint pass.

Checklist

  • This PR makes changes to the public API
  • Links for closing relevant issue numbers are included (Closes #752)

@sivaraman-krishnan sivaraman-krishnan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for picking up #752, @yuminn-k. Pulling the client_authentication switch into one helper is a nice cleanup. I checked that the three exchange methods behave as before: same parameter order, same client_id placement, same missing-secret check and message, and the same assertion audience. Public clients on the default client_secret_post with no secret still revoke with just client_id, so the common SPA case is unchanged. I ran the tests locally: the new Basic and JWT revoke tests fail on main and pass here, and the POST test passes on both as a guard.

One thing I think needs a change before merge, in the client_secret_jwt path for revocation (inline comment): the assertion's aud becomes the revocation endpoint URL, which at least Keycloak doesn't accept.

A smaller, pre-existing point that this PR now also applies to revocation: CryptoUtils.generateBasicAuth Base64-encodes client_id:client_secret without form-urlencoding the two values first, as RFC 6749 §2.3.1 asks. So a + in either value can be decoded as a space, and a : in the client ID can be mistaken for the separator. It affects the token requests too, so it probably belongs in its own issue rather than this PR.

Comment thread src/TokenClient.ts
if (this._settings.client_secret) {
params.set("client_secret", this._settings.client_secret);
}
const basicAuth = await this._applyClientAuthentication(params, url, this._settings.client_id, this._settings.client_secret);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

With client_secret_jwt, url here is the revocation endpoint, and _applyClientAuthentication passes it to generateClientAssertionJwt as the assertion's aud. The three token requests pass the token endpoint, which is also what generateClientAssertionJwt's doc comment describes ("The token endpoint URL (audience)").

Two things point the same way here. First, RFC 10070 §4 (November 2026) replaces the RFC 7523 §3 audience rule: for client authentication, aud "MUST use the issuer identifier [RFC8414] of the authorization server as its sole value". Its Operational Considerations say a client doing this interoperates with servers built to the earlier rules, though some providers still document endpoint-specific audiences, so it's worth keeping an eye on. Second, in practice: in Keycloak 26.4.0, client-secret-jwt (JWTClientSecretAuthenticator) uses JWTClientValidator, whose getExpectedAudiences accepts the issuer, token, introspection, PAR and CIBA URLs but not the revocation URL. So a client whose token requests work would have its client authentication rejected on revoke.

Could we keep the POST going to the revocation endpoint, but use the issuer (await this._metadataService.getIssuer()) as the assertion audience, for example via a separate audience parameter on _applyClientAuthentication? It's only needed in the JWT case, and Keycloak accepts the issuer. getIssuer() reads it from configured or discovered metadata, and throws if it's missing rather than silently falling back to an endpoint URL, which seems like the right failure mode. The token requests still use the token endpoint as aud, which RFC 10070 now also rules out for client authentication. That's probably a separate change (maybe with a setting for servers that only accept the token endpoint), so I wouldn't block this PR on it.

Comment thread src/TokenClient.test.ts
subject = new TokenClient(new OidcClientSettingsStore(settings), metadataService);
vi.spyOn(subject["_metadataService"], "getRevocationEndpoint")
.mockResolvedValue("http://sts/revoke_endpoint");
vi.spyOn(CryptoUtils, "generateClientAssertionJwt")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since generateClientAssertionJwt is mocked, this test passes whatever audience is used. Mocking getIssuer to a value different from the revocation URL (for example http://sts) and asserting expect(CryptoUtils.generateClientAssertionJwt).toHaveBeenCalledWith("client_id", "client_secret", "http://sts", "HS256") would lock in the audience. "HS256" is the settings default for token_endpoint_auth_signing_alg.

This branch has not been deployed

No deployments
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.

Revoke Token Request doesn't respect client_authentication settings

2 participants