Running into issues when attempting to get tokens using oauth

b33samab33sama Member Posts: 1

I have successfully gotten the code in the redirect uri I specified. But when making a call to get the access_token, I just get

{
  "error": "unsupported_grant_type"
}

This is the sample api call I am making

URL: https://api.waveapps.com/oauth2/token/
METHOD: POST
HEADERS: Content-type: application/json
data: {
  "grant_type": "authorization_code",
  "redirect_uri": "http://localhost:8002/wavesapps/auth-response",
  "code": "3jmsOxsVm5rRV43VdI4AM0J7N9gvkg",
  "client_id": "************************,
  "client_secret": "*******************"
}

Am I missing anything? The same error is what I get when I remove any of the fields so I am suspecting I am missing something.

Comments

  • RobVGRobVG Member Posts: 53 admin

    Hi @b33sama,

    Instead of providing the Content-type header as application/json, can you try using application/x-www-form-urlencoded or multipart/form-data.

    curl --location --request POST 'https://api.waveapps.com/oauth2/token/' \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode 'client_id=******' \
    --data-urlencode 'client_secret=******' \
    --data-urlencode 'code=******' \
    --data-urlencode 'grant_type=authorization_code' \
    --data-urlencode 'redirect_uri=http://localhost:8002/wavesapps/auth-response'
    
    edited January 23, 2020
  • ShivaputraShivaputra Member Posts: 1
    Hi @RobVG
    Can you help me with php curl request example for the same because i am getting 405 error response.

    here sample php code
    `
    <?php

    $curl = curl_init();

    curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://api.waveapps.com/oauth2/token',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => 'code=****&client_id=****************&client_secret=***********&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%2Fsignals%2Fauthentication%2FwaveRedirect',
    CURLOPT_HTTPHEADER => array(
    'Content-Type: application/x-www-form-urlencoded',
    'Cookie: AWSALB=CNznERhwE3vU8CnKanEIW96qxX2KJEzImnsTdAgNh3cmnigprfzbKxF2HIZNT2Zl3bzxVI2/ucoEDho7UOq/GnkExcGYPdqfrp6xLHnMWEEX8+5nEMIhDr5gJlx4; AWSALBCORS=CNznERhwE3vU8CnKanEIW96qxX2KJEzImnsTdAgNh3cmnigprfzbKxF2HIZNT2Zl3bzxVI2/ucoEDho7UOq/GnkExcGYPdqfrp6xLHnMWEEX8+5nEMIhDr5gJlx4'
    ),
    ));

    $response = curl_exec($curl);

    curl_close($curl);
    echo $response; `
    edited June 18, 2021
  • KieronBKieronB Member Posts: 13 admin

    Hi @Shivaputra

    Can you add a trailing slash to the URL so that the line reads:

    CURLOPT_URL => 'https://api.waveapps.com/oauth2/token/',

    I needed to make that change in order for your code example to work for me.

    One possible cause of the 405 HTTP status code you are receiving is a mismatch between the 'redirect_uri' sent in the request and the value(s) configured for your API application here. It could be worth double-checking that there isn't a typo in one place or the other.

    Also, keep in mind that even when this request fails, it will often "use up" the code retrieved in the first step of the oauth process, so you'll need to generate a new code each time.

    Hope this helps!

    Kieron

    edited June 23, 2021
Sign In or Register to comment.