Skip to main content
Question

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

  • November 16, 2023
  • 1 reply
  • 280 views

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.

<?php

// Load required files and classes
require 'vendor/autoload.php';
use RingCentralSDKSDK;

// Load environmental file
$dotenv = DotenvDotenv::createImmutable(__DIR__);
$dotenv->load();

// 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 RingCentralSDKSDK( $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 reply

PhongVu
Community Manager
Forum|alt.badge.img
  • Community Manager
  • November 16, 2023

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.