Can not change refresh_token

  • 1
  • Problem
  • Updated 7 months ago
Hello, i use the library https://github.com/ringcentral/ringcentral-php.
$apiResponse = $rcsdk->platform()->post('/restapi/oauth/token', [
'refresh_token' => $data['refresh_token'],
'grant_type' => 'refresh_token',
'endpoint_id' => $_ENV['RC_AppKey']
]);

I get a response from the server, Unsupported grant type. What is the problem?
Photo of Alexey Shpilka

Alexey Shpilka

  • 324 Points 250 badge 2x thumb

Posted 7 months ago

  • 1
Photo of Phong Vu

Phong Vu, Devangelist

  • 3,212 Points 3k badge 2x thumb
Hi Alexey,

Why do you want to change the refresh token? After logged in, if the access token expired, you can call $rcsdk->platform()->refresh() to refresh the access token. If the refresh token also expired, you just need to call $rcsdk->platform()->login($option) again.

You can always check if the access token and the refresh token is still valid or not to decide what to do by calling $rcsdk->auth()->accessTokenValid() or $rcsdk->auth()->accessTokenValid(), respectively.

+ Phong
Photo of Alexey Shpilka

Alexey Shpilka

  • 324 Points 250 badge 2x thumb
We need automation of the process, is it possible to authorize without entering a username and password?
Photo of John Wang

John Wang, Official Rep

  • 5,664 Points 5k badge 2x thumb
Alexey,

Can you verify that your app has the "Refresh Access Token" flow grant which is required to refresh your token? I will look like the following in the "Settings" > "OAuth Settings" > "Authorization Flows" section of your app configuration as shown below:



Thanks,
John
(Edited)
Photo of Tyler Long

Tyler Long, Official Rep

  • 8,492 Points 5k badge 2x thumb
Instead of the code you post, could you please try `$rcsdk->platform()->refresh()` instead? Because the PHP SDK already provides method for refreshing.
Photo of Alexey Shpilka

Alexey Shpilka

  • 324 Points 250 badge 2x thumb
I will write in the language of the zoho deluge
Photo of Alexey Shpilka

Alexey Shpilka

  • 324 Points 250 badge 2x thumb
the last mistake I received, { "message" : "Unsupported Media Type", "errors" : [ ] }
Photo of Alexey Shpilka

Alexey Shpilka

  • 324 Points 250 badge 2x thumb
I understood what the problem was not to use urlencoded
Photo of Tyler Long

Tyler Long, Official Rep

  • 8,492 Points 5k badge 2x thumb
If I was you, I would choose Ruby instead of PHP for Proof of concept. You have to rewrite the code in zoho deluge anyway. So you just choose the language which could help you to get things done very quickly.

I am not telling you that Ruby is quicker to write than PHP. Because we have an official Ruby SDK which is 10 times simpler than the PHP SDK. (Disclaimer: I am the author of the Ruby SDK while I am not the author of the PHP SDK).

By reading the Ruby SDK's source code here, you can quickly figure out everything you need to know.  https://github.com/ringcentral/ringcentral-ruby/blob/master/lib/ringcentral.rb

For example: by reading https://github.com/ringcentral/ringcentral-ruby/blob/master/lib/ringcentral.rb#L159  You will know that before you get the token, you should use basic header, and after you get the token you should use bearer token instead.
(Edited)