question

andrew-auger13595 avatar image
andrew-auger13595 asked Byrne Reese edited

Receiving "unauthorized_client" error when using php curl for auth/token

{    
  "error" : "unauthorized_client",    
  "error_description" : "Unauthorized for this grant type",    
  "errors" : [ {      
    "errorCode" : "OAU-251", 
    "message" : "Unauthorized for this grant type"    
  } ] 
}

Here is my code below:-


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://platform.devtest.ringcentral.com/restapi/oauth/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=+12048184079&password=Reset321$$&extension=101&grant_type=password");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "1RjNgM-LTxxxxxFuE-ggrHA" . ":" . "524fjcxxxxxxxxxxCPclIZHxxxxxx_FdfegzA");

$headers = array();
$headers[] = "Accept: application/json";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);

echo '<pre>'; print_r($result); die;

if (curl_errno($ch)) {

echo 'Error:' . curl_error($ch);
}

curl_close ($ch);



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.

igor-bebin avatar image
igor-bebin answered
Hi Andrew,

The following grant types are available for your application: 
* Authorization Code
* Refresh Access Token

Please find instructions on how to use these flows:
https://developers.ringcentral.com/api-reference#OAuth-2-0
https://ringcentral-api-docs.readthedocs.io/en/latest/oauth/#authorization-flows

Thanks,
Igor
1 |1000

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

andrew-auger13595 avatar image
andrew-auger13595 answered Tyler Liu commented
can you correct my code or give me the exact code according to my php curl for this error

1 comment
1 |1000

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

Tyler Liu avatar image Tyler Liu commented ·
If you want to use password flow, you need to create a new app which supports password flow.
0 Likes 0 ·
Anirban Sen Chowdhary avatar image
Anirban Sen Chowdhary answered

The screenshot shared by you seems you have created application of platform type server/ web which supports grant_type=Authorization code while you are trying grant_type=password.

You need to create application that support grant_type,=password or password flow in ring central terms

1 |1000

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

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.