Fix missing Content-Type header on OAuth token request#49
Open
jacksonhuether wants to merge 1 commit intofragment-dev:devfrom
Open
Fix missing Content-Type header on OAuth token request#49jacksonhuether wants to merge 1 commit intofragment-dev:devfrom
jacksonhuether wants to merge 1 commit intofragment-dev:devfrom
Conversation
The create_token method sends a form-encoded POST body but does not set the Content-Type header to application/x-www-form-urlencoded. Some OAuth servers (including AWS Cognito) return 405 Method Not Allowed when the header is absent because they cannot identify the request as a valid form POST. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
create_tokenmethod inFragmentClientsends a form-encoded POST body for the OAuth client credentials grant, but does not explicitly set theContent-Typeheader toapplication/x-www-form-urlencoded.While some OAuth servers infer the content type from the body, others — including AWS Cognito — strictly require the header to be present. Without it, these servers return 405 Method Not Allowed because they cannot identify the request as a valid form POST.
Fix
Added
post.content_type = "application/x-www-form-urlencoded"to thecreate_tokenmethod, afterbasic_authis set and before the body is assigned. This is a one-line, non-breaking change that makes the request conformant with RFC 6749 Section 4.4.2, which specifies that client credentials grant requests useapplication/x-www-form-urlencoded.Changes
lib/fragment_client.rb: SetContent-Type: application/x-www-form-urlencodedon the token request.