Skip to content

Send token revocation request as POST with form-encoded body - #624

Draft
rootkiller6788 wants to merge 1 commit into
google:mainfrom
rootkiller6788:fix-revoke-token-post
Draft

Send token revocation request as POST with form-encoded body#624
rootkiller6788 wants to merge 1 commit into
google:mainfrom
rootkiller6788:fix-revoke-token-post

Conversation

@rootkiller6788

Copy link
Copy Markdown

Problem

disconnectWithCompletion: built a revocation URL with the token in the query string (/o/oauth2/revoke?token=...) and fetched it via startFetchURL:, which creates an NSMutableURLRequest without setting HTTPMethod, so the request went out as GET.

Google's OAuth2 token revocation docs and RFC 7009 section 2.1 both specify a POST request carrying the token in a form-encoded body.

Fixes #621.

Changes

  • Add kHTTPMethodPost and kContentTypeFormURLEncoded constants.
  • Generalize startFetchURL: to accept an HTTP method and optional body; the userinfo fetch keeps using GET with no body.
  • Build the revocation request as POST with the token (and logging parameters) in an application/x-www-form-urlencoded body, reusing the existing NSURLComponents/GIDPercentEncodePlusInQuery encoding so a literal + in a token survives form decoding.
  • Extend GIDFakeFetcher to expose the request HTTP method and body.
  • Update the disconnect unit tests to assert the method is POST and the token/logging parameters are in the decoded body rather than the query string.

Testing

Updated the existing disconnect unit tests in GIDSignInTest.m to cover the new POST + form body behavior, including the token-percent-encoding cases (reserved characters, +, and space).

The disconnect flow built a revoke URL with the token in the query string
and fetched it with the default GET method. Google's OAuth2 token
revocation endpoint (and RFC 7009 section 2.1) requires a POST request
carrying the token in a form-encoded body.

Generalize startFetchURL: to accept an HTTP method and body, use POST with
a form-encoded body for revocation, and update the disconnect tests to
assert the method and body instead of the query string.
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.

Revoke request uses GET instead of POST

1 participant