Skip to content

fix: only allow one authenticate method#858

Open
suqin-haha wants to merge 7 commits intozitadel:mainfrom
suqin-haha:main
Open

fix: only allow one authenticate method#858
suqin-haha wants to merge 7 commits intozitadel:mainfrom
suqin-haha:main

Conversation

@suqin-haha
Copy link
Copy Markdown

@suqin-haha suqin-haha commented Mar 18, 2026

according to the RFC 6749 §2.3 The client MUST NOT use more than one authentication method in each request.

this PR resolve issue #857

  1. add the logic to only have one authenticate method in client side
  2. add the restrict on the OP side to only allow one authenticate method.

NOTE: it's a breaking change since it removes ClientSecretBasicAuthRequest interface and func Auth( code.

test:
added united test

Definition of Ready

  • I am happy with the code
  • Short description of the feature/issue is added in the pr description
    - [ ] PR is linked to the corresponding user story
  • Acceptance criteria are met
    - [ ] All open todos and follow ups are defined in a new ticket and justified
    - [ ] Deviations from the acceptance criteria and design are agreed with the PO and documented.
  • No debug or dead code
  • My code has no repetitions
  • Critical parts are tested automatically
    - [ ] Where possible E2E tests are implemented
    - [ ] Documentation/examples are up-to-date
  • All non-functional requirements are met
    - [ ] Functionality of the acceptance criteria is checked manually on the dev system.

Comment thread pkg/client/client.go
@suqin-haha suqin-haha requested a review from muir March 25, 2026 16:32
Comment thread pkg/client/client.go Outdated
Comment thread pkg/client/client.go
Comment thread pkg/client/client.go
@suqin-haha suqin-haha requested a review from muir March 31, 2026 12:54
@muhlemmer
Copy link
Copy Markdown
Collaborator

@wim07101993 can you please review this PR?

@muhlemmer muhlemmer requested review from wim07101993 and removed request for muir March 31, 2026 16:53
Comment on lines -819 to -823
func (r RefreshTokenRequest) Auth(req *http.Request) {
if r.ClientSecret != "" {
req.SetBasicAuth(r.ClientID, r.ClientSecret)
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Removing this method creates a breaking change. Both in changing the public api and removing the implementation of the ClientSecretBasicAuthRequest interface. Wouldn't there be another solution without breaking changes?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

it's a wrong behavior we should mark the release as broken or bug ASAP.

I don't have any idea to fix it without breaking change. Does any one have a good migration idea?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@muhlemmer what do you think about this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

any update on that issue?
feel free to bring up migration idea.
Or we might need to make it as a break change release?

Comment thread pkg/op/token_request.go
@wim07101993
Copy link
Copy Markdown
Member

@suqin-haha thank you for the contribution. Could you have a look at my comments?

@wim07101993 wim07101993 self-assigned this Apr 9, 2026
@wim07101993 wim07101993 moved this to 👀 In review in Product Management Apr 9, 2026
wim07101993 pushed a commit that referenced this pull request Apr 17, 2026
…873)

## Summary

Four `Auth()` methods call `req.SetBasicAuth()` with raw client
credentials. Per [RFC 6749 Section
2.3.1](https://datatracker.ietf.org/doc/html/rfc6749#section-2.3.1),
client credentials MUST be encoded using the
`application/x-www-form-urlencoded` encoding algorithm before being sent
via HTTP Basic Authentication.

`net/http.SetBasicAuth` only base64-encodes the credentials — it does
not URL-encode them first. When a client secret contains characters like
`%`, authorization servers that URL-decode per the RFC (e.g., Keycloak)
fail with errors like `URLDecoder: Incomplete trailing escape (%)
pattern`.

The existing `AuthorizeBasic()` helper in `pkg/http/http.go` already
correctly applies `url.QueryEscape`. This PR applies the same encoding
to the four `Auth()` methods that were missing it:

- `RefreshTokenRequest.Auth` (`pkg/client/rp/relying_party.go`)
- `RevokeRequest.Auth` (`pkg/client/client.go`)
- `DeviceAccessTokenRequest.Auth` (`pkg/client/client.go`)
- `ClientCredentialsRequest.Auth` (`pkg/oidc/token_request.go`)

## Related

This is distinct from #857 / #858 (duplicate credentials issue), though
both stem from the same `Auth()` methods. This PR fixes the encoding bug
without removing the `ClientSecretBasicAuthRequest` interface, so it is
not a breaking change.

## Testing

All existing tests pass. The fix is a one-line change per method,
consistent with the pattern already used by `AuthorizeBasic()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

5 participants