News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
PHP - OAU-251 error - Unauthorized for this grant type
Tags: authentication, auth
Nov 16, 2023 at 12:11pm   •   1 replies  •  0 likes
Gabriela Andrade

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 RingCentral\SDK\SDK;

// Load environmental file
$dotenv = Dotenv\Dotenv::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 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 Answer
answered on Nov 16, 2023 at 12:36pm  

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.


 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us