Skip to content

Fix OAuth token request using full URL as HTTP request path#45

Merged
snoble merged 3 commits intofragment-dev:devfrom
jacksonhuether:fix/oauth-token-request-path
Feb 25, 2026
Merged

Fix OAuth token request using full URL as HTTP request path#45
snoble merged 3 commits intofragment-dev:devfrom
jacksonhuether:fix/oauth-token-request-path

Conversation

@jacksonhuether
Copy link
Contributor

Summary

create_token passes the full URL to Net::HTTP::Post.new(uri.to_s), which causes the entire URL (e.g. https://auth.us-east-1.fragment.dev/oauth2/token) to be used as the HTTP request path instead of just /oauth2/token.

The raw HTTP request line ends up as:

POST https://auth.us-east-1.fragment.dev/oauth2/token HTTP/1.1

instead of:

POST /oauth2/token HTTP/1.1

Some servers — notably AWS Cognito behind CloudFront — do not handle absolute-form request URIs and misroute the request, returning 405 Method Not Allowed (allow: GET).

Fix

Replace uri.to_s with uri.request_uri, which returns just the path and query string (/oauth2/token).

- post = Net::HTTP::Post.new(uri.to_s)
+ post = Net::HTTP::Post.new(uri.request_uri)

jacksonhuether and others added 3 commits February 24, 2026 15:40
`Net::HTTP::Post.new(uri.to_s)` passes the full URL
(e.g. `https://auth.us-east-1.fragment.dev/oauth2/token`) as the HTTP
request path instead of just the path component (`/oauth2/token`).

This causes the raw HTTP request line to be:

    POST https://auth.us-east-1.fragment.dev/oauth2/token HTTP/1.1

Some servers (notably AWS Cognito behind CloudFront) do not handle
absolute-form request URIs and misroute the request, returning
405 Method Not Allowed.

Fix by using `uri.request_uri` which returns just the path and query
string components.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Validates the token request against RFC 7230 §5.3.1 (origin-form
request-target) and RFC 6749 §4.4.2/§2.3.1 (client credentials grant
format, HTTP Basic authentication). Intercepts Net::HTTP::Post to
verify the raw request path since WebMock normalizes URLs and cannot
detect absolute-form vs origin-form request-targets.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@snoble snoble closed this Feb 25, 2026
@snoble snoble reopened this Feb 25, 2026
@snoble
Copy link
Contributor

snoble commented Feb 25, 2026

Thank you @jacksonhuether

@snoble snoble merged commit 23a3ff7 into fragment-dev:dev Feb 25, 2026
3 checks passed
@snoble snoble mentioned this pull request Feb 25, 2026
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.

3 participants