Repository navigation
Conversation
sivaraman-krishnan
left a comment
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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.
| subject = new TokenClient(new OidcClientSettingsStore(settings), metadataService); | ||
| vi.spyOn(subject["_metadataService"], "getRevocationEndpoint") | ||
| .mockResolvedValue("http://sts/revoke_endpoint"); | ||
| vi.spyOn(CryptoUtils, "generateClientAssertionJwt") |
There was a problem hiding this comment.
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.
Closes #752
TokenClient.revoke()always putclient_secretin the request body and never passedbasicAuthtopostForm, so it ignored theclient_authenticationsetting that the code, credentials and refresh-token requests honour.With this change, the
client_authenticationswitch that was repeated inexchangeCode,exchangeCredentialsandexchangeRefreshTokenmoves into one private helper (_applyClientAuthentication), as suggested in the issue.revoke()now uses it too:client_secret_basic:Authorization: Basic ...header, noclient_secretin the bodyclient_secret_post:client_idandclient_secretin the body (same as before)client_secret_jwt:client_assertionin the body instead of the rawclient_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, sorevoke()now throws it forclient_secret_basic/client_secret_jwtwithout a secret, like the other requests. With the defaultclient_secret_postnothing 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
Closes #752)