2238
Views
5
Comments
Solved
[Google Services OAuth2] Error "unsupported_grant_type" and "Invalid grant_type"
google-services-oauth2
Web icon
Forge asset by João 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


2018-10-11 12-39-16
Ruben Machado
Solution

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.


2018-10-11 12-39-16
Ruben Machado

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

2019-09-17 09-11-00
João Pedro Abreu
Staff

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.

2018-10-11 12-39-16
Ruben Machado

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"?


2019-09-17 09-11-00
João Pedro Abreu
Staff

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.


2018-10-11 12-39-16
Ruben Machado
Solution

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.


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.