Gabriela Andrade avatar image
Gabriela Andrade asked Phong Vu answered

PHP - OAU-251 error - Unauthorized for this grant type

I have read through the previous posts concerning this subject, but have not found a solution that works for my project. My app settings are set to the JWT auth flow, and I have double-checked my credentials. I was able to connect to the API using those credentials with an Ajax call in node.js, but now we are pivoting to using a PHP backend to make the calls.

I have set up the JWT auth call following the steps in the developer documentation, with the RingCentral PHP SDK installed; however, whenever I run the code, it serves the OAU-251 "Unauthorized for this grant type" error. What am I missing?

Here is my code.

The time variables in the function are to be used later and are not used in the auth request; I have commented them out while testing to ensure those are not somehow causing errors in the auth portion.

I have also tried using both the encoded and unencoded version of the client_id and client_secret.


// Load required files and classes
require 'vendor/autoload.php';
use RingCentral\SDK\SDK;

// Load environmental file
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);

// Get environmental variables
$client_id = $_ENV['CLIENT_ID'];
$client_secret = $_ENV['CLIENT_SECRET'];
$rc_url = $_ENV['RC_SERVER_URL'];
$api_key = $_ENV['API_KEY'];

function dataRefresh($client_id, $client_secret, $rc_url) {

    // Set time variables for requests
    $start = substr(date("c", strtotime("- 1 minute")), 0, -9);
    $end = substr(date("c"), 0, -9);
    // Base 64 encode client_id and client_secret
    $encoded_id = base64_encode($client_id);
    $encoded_secret = base64_encode($client_secret);

    // JWT Authorization
    $rcsdk = new RingCentral\SDK\SDK( $client_id, $client_secret, $rc_url );
    $platform = $rcsdk->platform();
    $platform->login( [ "jwt" => $_ENV['RC_JWT'] ] );

    // Make access token available in scope
    $access_token = $_ENV['RC_JWT'];
    //echo $access_token;

dataRefresh($client_id, $client_secret, $rc_url);
1 |3000

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

1 Answer

Phong Vu avatar image
Phong Vu answered

Did you update the RingCentral PHP SDK? Make sure that you have the newer SDK version that supports JWT.

Let me know if it still does not work.

1 |3000

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

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys