Skip to content

oauth: fix request construction and cancellation - #2499

Merged
mjcheetham merged 3 commits into
git-ecosystem:mainfrom
mjcheetham:oauth-fixups
Nov 9, 2026
Merged

mjcheetham merged 3 commits into
git-ecosystem:mainfrom
mjcheetham:oauth-fixups

Conversation

@mjcheetham

Copy link
Copy Markdown
Contributor

Correct several discrepancies between the shared OAuth2 client’s request construction and RFC 6749 §3.2.1 and RFC 8628 §3.1, separately from the token-exchange feature.

Client credentials could previously be sent through both HTTP Basic and the request body, contrary to RFC 6749 §2.3’s prohibition on multiple authentication methods per request. Apply the configured method consistently to token and device-authorization requests, omit unconfigured secrets (§2.3.1), and retain body client_id for client identification.

Stop sending redirect_uri during refresh requests and remove the test server’s corresponding requirement. Authorization-code requests continue to repeat the original redirect URI when it was supplied during authorization, as required by RFC 6749 §4.1.3.

Also propagate cancellation to response-body reads. The OAuth client’s LF line-ending normalization is kept in a separate commit so the functional changes remain easy to review.

We typically store files with the LF line ending in our repo. The OAuth
client file was stored with CRLF in error. Fix that.

Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
RFC 6749 states that a client MAY send client credentials (client ID +
client secret) in either the `Authorization` header, or as part of the
request body (such as in form data).

However, the RFC also states a client MUST NOT send the client
credentials in both the request body AND the `Authorization` header at
the same time. We must make sure we only send credentials in the header
if configured so, and therefore also only send credentials in the body
if not.

Additionally, depending on the implementation of the authorization server,
public clients need not send a client secret either in the request body
or `Authorization` header. If we have no real value, we should not send
the credentials. Note that the client ID is always required, and may be
present in the request body even if the credentials are sent in the
`Authorization` header, so let's always still send the client ID in the
body.

Finally, we have also been sending the redirect URI in the request body
for flows/endpoints that did not require them - stop doing that.
According to RFC 6749 only the authorization code request needs a
redirect URI to be sent, and also in the corresponding token request.

Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
We have a cancellation token from the caller, but we have not been
passing this down to the `Content.ReadAdStringAsync()` operation on the
HTTP responses. Let's do this.

Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
@mjcheetham
mjcheetham requested a review from a team as a code owner November 9, 2026 13:48
@mjcheetham mjcheetham added the auth:oauth Specific to OAuth2 authentication label Nov 9, 2026

@dscho dscho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks obviously correct to me.

@mjcheetham

Copy link
Copy Markdown
Contributor Author

I should add that I tested these changes against GitHub, GitLab, Bitbucket, and Gitea's hosted servers.

@mjcheetham
mjcheetham merged commit 7b5c73f into git-ecosystem:main Nov 9, 2026
23 of 24 checks passed
@mjcheetham
mjcheetham deleted the oauth-fixups branch November 9, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth:oauth Specific to OAuth2 authentication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants