[Google Services OAuth2] Error "unsupported_grant_type" and "Invalid grant_type"

Forge Component
(3)
Published on 13 Mar by João Pedro Abreu
3 votes
Published on 13 Mar by João Pedro Abreu

Hi all,

I'm trying integrate to the Google Services OAuth2 component, but, I'm having some troubles exchanging the code (that it's received in the first step) by a token.

Using a valid code, triggering the request by the REST API Method, the response returns:

{  "error": "unsupported_grant_type",  "error_description": "Invalid grant_type: "}:



Any suggestion?

Thanks


Changing the order of "&", with the same inputs, the response returns another error:


The redirect_uri matches with the configured one in the API Console.

Any suggestion?

Thanks

Hi Ruben,

The issue with your test (and the example that's already defined in the code) is that it has line breaks between each parameter. if you delete all the line breaks, leaving all values in a single row, your test will work.

The reason this component actually works in runtime, despite having the message body defined like in your screenshot, is that the OutSystems platform ignores that message body and sends a valid one based solely on the method's input parameters.

Hi João,

Thanks for your input. I've tried sending all values in the same line, and the response on outsystems was the same. The monitoring on service center returns:

400 Bad Request
   at ssGoogleServicesOAuth2.CcGoogleApis.ActionAccessTokenGet(HeContext heContext, ICcGoogleApisCallbacks _callbacks, String inParamcode, String inParamclient_id, String inParamclient_secret, String inParamredirect_uri, String inParamgrant_type, STAccessTokenResponseStructure& outParamResponse)

Is supposed to encode the code send in the request? To send "4%2AAAA" instead of "4/AAAA"?


That’s odd. I think the value should be URL encoded. By the way, the Test values shouldn’t be between parentheses.

Do you have an error in runtime? If so, maybe setting the integration logs to “Full” and looking at the integration logs will help.


Hi João,

Thanks for your help!

Basically I was failing in the following steps:

- The request has to have the following structure (all inputs in the same line):
code={code}&client_id={client_id}&client_secret={client_secret}&redirect_uri={redirect_uri}&grant_type=authorization_code&

- The code isn't encoded, is directly addressed to the input.

- The redirect_uri has to be the same as the send in the first step.