Hi,
I am trying to invoke the Google OAuth 2.0 to retrieve the access token by providing the authorisation code, client id ,grant type,secret key,redirect uri from a service call out policy.
I managed to get the Authorisation code from the Google OAuth , but the POST request to get the access token fails with
{
"fault": {
"detail": {
"errorcode": "steps.servicecallout.ExecutionFailed"
},
"faultstring": "Execution of ServiceCallout GetThirdPartyAccessToken failed. Reason: ResponseCode 400 is treated as error"
}
}
However when I tried the same POST request with the authorisation code and other parameters via CURL, I am able to get the access token back successfully.
curl -X POST [https://www.googleapis.com/oauth2/v3/token](https://www.googleapis.com/oauth2/v3/token) \
-d "grant_type=authorization_code&code=4/bVMzsBtBCIKZ7c1WSgxZUf2kIjbSIRJ3vxEdz2Gufqk&client_id=Client_ID_HERE&client_secret=VERY_SECRET&redirect_uri=myredirectURI"
Find below my ServiceCall Out.
I am not sure , if the Google OAuthAPI accepts a json payload.(Pls correct me )
<ServiceCallout name="GetThirdPartyAccessToken">
<Request variable="googleAuthRequest">
<Set>
<Headers>
<Header name="Accept">application/json</Header>
</Headers>
<Payload contentType="application/json" variablePrefix="$" variableSuffix="%"> {
"code": "$request.queryparam.code%"
"client_id":"myclient id"
"client_secret":"mysecret"
redirect_uri:"my redirect uri"
"grant_type":"authorization_code"
}
</Payload>
<Verb>POST</Verb>
</Set>
</Request>
<Response>calloutResponse</Response>
<Timeout>30000</Timeout>
<HTTPTargetConnection>
<Properties/>
<URL>https://www.googleapis.com/oauth2/v3/token</URL> </HTTPTargetConnection>
</ServiceCallout>
Could you please help me correcting my service call out to Google OAuthAPI to get the AccessToken via a POST request?