question

tayyab-sajjad6063 avatar image
tayyab-sajjad6063 asked Tyler Liu commented

where to use access_token

Is there anyone who can help me in using Access_token in my PHP Web Application.
right now i am stuck on access_token and i want to test my Fax function but Using PHP SDK i am stuck on Refresh_token function it is giving error and looks like my SDK is not using Access_token....


i am getting this error
authData.php Auth exception: Refresh token has expired Exception: Unauthorized for this grant type SDK HTTP Error at https://platform.devtest.ringcentral.com/restapi/oauth/token Response text: { "error" : "unauthorized_client", "error_description" : "Unauthorized for this grant type", "errors" : [ { "errorCode" : "OAU-251", "message" : "Unauthorized for this grant type" } ] }
topic-default
1 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

paco-vu avatar image
paco-vu answered
Hi Tayyab,

It seems you selected the wrong Platform type (other types than the "Server-only/(No UI)" for your RingCentral app. If your Web app uses the PHP SDK to authenticate and access RingCentral APIs directly, you must select the "Server-only/(No UI)" for the Platform type.

Try to create a new app with that platform type and test again.

Kind regards,
Paco
1 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

tayyab-sajjad6063 avatar image
tayyab-sajjad6063 answered Tyler Liu commented
i have created another app with Server no UI but now i am not able to authorize it 
26 comments
1 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

paco-vu avatar image paco-vu commented ·
1) You still receiving the same error which related to wrong platform type. So I am not sure if you have changed the appKey and secret accordingly.

2) I saw your other questions relating to problem with sending fax from PHP code and there you mentioned about using 3-leg authentication. If this is the same project, then you probably don't need to create a new app with "server-only" platform type. But you should follow the instructions from this demo project to get the access token from your client side and pass the token to the php via session.

https://github.com/ringcentral/ringcentral-demos-oauth/blob/master/php/index.php

//set the access token using the auth objectif (isset($_SESSION['sessionAccessToken'])) { $platform->auth()->setData((array)json_decode($_SESSION['sessionAccessToken']));}

Hope this helps,
Paco
1 Like 1 ·
paco-vu avatar image paco-vu commented ·
It would be helpful to diagnose if you can show a little more with your codes?
0 Likes 0 ·
tayyab-sajjad6063 avatar image tayyab-sajjad6063 commented ·
when i get the access_token after that how to use that token ?
Do you know ?
try {

    $platform->refresh();

    print 'Authorization was restored' . PHP_EOL;

} catch (Exception $e) {

    print 'Auth exception: ' . $e->getMessage() . PHP_EOL;

    $auth = $platform->login($credentials['username'], $credentials['extension'], $credentials['password']);

    print 'Authorized' . PHP_EOL;

}


when i try to run this code , it failed at refresh token and give this error
authData.php Auth exception: Refresh token has expired Exception: Unauthorized for this grant type SDK HTTP Error at https://platform.devtest.ringcentral.com/restapi/oauth/token Response text: { "error" : "unauthorized_client", "error_description" : "Unauthorized for this grant type", "errors" : [ { "errorCode" : "OAU-251", "message" : "Unauthorized for this grant type" } 


0 Likes 0 ·
tayyab-sajjad6063 avatar image tayyab-sajjad6063 commented ·
i am passing this but after this action when i try to refresh token or login it is getting failed...
and using the same $platform any api request is also failed.

help me
0 Likes 0 ·
ak avatar image ak commented ·
If the accessToken is expired, then you would HAVE to Authorize the same way as you did earlier using the Authorization Code Flow ( 3 Legged OAuth )

Since the accessToken are valid for 1 hour and if you are trying to refresh the tokens before the TTL expiry then you are GOOD to refresh the accessTokens. But once the accessTokens are expired you would no longer be able to refresh the expired token and hence you would need to re-authorize again

Are you following the API ref for Refresh:
https://developer.ringcentral.com/api-docs/latest/index.html#!#RefRefreshTokenFlow


0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.