We are writing a web application that, among other things, will use the calendar API to retrieve data and add events to a couple calendars, but we're running into a problem using OAuth2. We get an error message at the final step, when we have received the authorization code and we are posting a request back to the OAuth server asking for the access token. This is described under "Handling the Response" in the documentation for usinf OAuth 2.0 for Web Server Applications [1].
The response we get to POSTing the request is a Net::HTTPBadRequest (i.e. error code 400) with a response body that says "Required parameter is missing: response_type". This seems suspicious because response_type is a parameter required in an earlier request but not in this step of the process.
ASIDE: We've tried a lot of silly things, such as including a "response_type" parameter in this request, though there's no documentation of that and therefore no indication of what value would be used at this point (using "response_type=access_token" returns an error saying "access_token" is an invalid value, but using "response_type=token" or "response_type=code" does not). If we supply a value for response_type, we next get another error saying we're missing the "scope" parameter. If we supply that, we get an error saying "client_secret" is not a valid parameter for this request. That suggests that the OAuth server is trying to treat this as a request for an authorization code rather than the later step of trying to exchange the authorization code for an access_token.
The error message also echos back the values that have been submitted for the five required parameters at this step, and they all look good. We've read various forum posts that discuss similar symptoms, but none seem to suggest anything that makes sense to this situation. This is being done in a Ruby-on-Rails app. We tried using Google's newest Ruby client, and we've written our own client using ActiveRecord::Connection to POST the request, and later we switched to using Net::HttpPost and Net::Http directly in case something in the Rails code was interfering. We can post code fragments and debugging output if that helps.
We'd appreciate any suggestions.
[1]
https://developers.google.com/accounts/docs/OAuth2WebServer#handlingtheresponse