Skip to main content
The First Step
December 1, 2022
Question

unable to use pwd or JWT authentication

I am not able to use JWT or "password based" authentication. I am always getting the error "unauthorized for this grant type".

17 replies

The First Step
December 8, 2022

Feel free to revoke my token and test with yours.

It seems not to be my php as I am having the same problem from the RingCentral Developer API Reference website:


2022-12-08-18-41-37-window.png

PhongVu
Community Manager
Community Manager
December 9, 2022

Thanks for allowing me to reset the token and run test on your sandbox. Here is the code that I ran successfully on your sandbox account with the new JWT token. Actually the old token should also work but I already revoke it so I can't verify that.

<?php
require('vendor/autoload.php');

$RINGCENTRAL_CLIENTID = 'XXXXX_a5Q';
$RINGCENTRAL_CLIENTSECRET = 'XXXXXXXRunH4rsv89g';
$RINGCENTRAL_SERVER = 'https://platform.devtest.ringcentral.com';

$JWT_TOKEN = 'eyJraWQiOiXXXXXXXXJuaFwenkYMPPxA';

$rcsdk = new RingCentralSDKSDK($RINGCENTRAL_CLIENTID, $RINGCENTRAL_CLIENTSECRET, $RINGCENTRAL_SERVER);

$platform = $rcsdk->platform();
try{
  $platform->login(["jwt" => $JWT_TOKEN]);
  $resp = $platform->get('/account/~/extension');
  foreach ($resp->json()->records as $record) {
      print_r (json_encode($record, JSON_PRETTY_PRINT));
  }
}catch (RingCentralSDKHttpApiException $e) {
  print 'Expected HTTP Error: ' . $e->getMessage() . PHP_EO
}

// Here is the response
{
    "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/75645xxxx/extension/34660xxxx",
    "id": 346608004,
    "extensionNumber": "102",
    "contact": {
        "firstName": "Mister",
        "lastName": "Test",
        "email": "xxx",
        "emailAsLoginName": true,
        "pronouncedName": {
            "type": "Default",
            "text": "Mister Test"
        }
    },
    "name": "Mister Test",
    "type": "User",
    "status": "NotActivated",
    "permissions": {
        "admin": {
            "enabled": false
        },
        "internationalCalling": {
            "enabled": true
        }
    },
    "profileImage": {
        "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/75645xxxx/extension/34660xxxx/profile-image"
    },
    "hidden": false
}{
    "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/75645xxxx/extension/34660xxxx",
    "id": 34660xxxx,
    "type": "User",
    "status": "Unassigned",
    "profileImage": {
        "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/75645xxxx/extension/34660xxxx/profile-image"
    },
    "hidden": true
}{
    "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/75645xxxx/extension/34661xxxx",
    "id": 34661xxxx,
    "type": "User",
    "status": "Unassigned",
    "profileImage": {
        "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/75645xxxx/extension/34661xxxx/profile-image"
    },
    "hidden": true
}{
    "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/75645xxxx/extension/75645xxxx",
    "id": 756456005,
    "extensionNumber": "101",
    "contact": {
        "firstName": "Peter",
        "lastName": "H",
        "company": "....",
        "email": "...",
        "businessPhone": "+1516849xxxx",
        "emailAsLoginName": true,
        "pronouncedName": {
            "type": "Recorded",
            "text": "Peter H",
            "prompt": {
                "id": "8931xxxx",
                "contentType": "audio/wav",
                "contentUri": "https://media.devtest.ringcentral.com/restapi/v1.0/account/75645xxxx/extension/75645xxxx/greeting/8931xxxx/content"
            }
        }
    },
    "name": "Peter H",
    "type": "User",
    "status": "Enabled",
    "permissions": {
        "admin": {
            "enabled": true
        },
        "internationalCalling": {
            "enabled": true
        }
    },
    "profileImage": {
        "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/75645xxxx/extension/75645xxxx/profile-image"
    },
    "hidden": false
}
The First Step
December 9, 2022

Thank you for all your help. I used your exact code (with your JWT token) and I am still getting the error: ( I even updated the SDK)

$ curl -sS https://getcomposer.org/installer | php

All settings correct for using Composer

Downloading...


Composer (version 2.2.18) successfully installed to: /app/www/composer.phar

Use it: php composer.phar


$ php composer.phar require ringcentral/ringcentral-php vlucas/phpdotenv

Info from https://repo.packagist.org: #StandWithUkraine

Using version ^2.2 for ringcentral/ringcentral-php

Using version ^4.3 for vlucas/phpdotenv

./composer.json has been updated

Running composer update ringcentral/ringcentral-php vlucas/phpdotenv

Loading composer repositories with package information

Updating dependencies

Lock file operations: 0 installs, 1 update, 0 removals

- Upgrading vlucas/phpdotenv (v4.2.2 => v4.3.0)

Writing lock file

Installing dependencies from lock file (including require-dev)

Package operations: 0 installs, 1 update, 0 removals

- Upgrading vlucas/phpdotenv (v4.2.2 => v4.3.0): Extracting archive

Generating autoload files

11 packages you are using are looking for funding.

Use the `composer fund` command to find out more!

$ php rc_test.php

PHP Notice: Undefined index: username in /app/www/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php on line 217

PHP Notice: Undefined index: extension in /app/www/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php on line 218

PHP Notice: Undefined index: password in /app/www/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php on line 219

Expected HTTP Error: Unauthorized for this grant type


What am I doing wrong?

PhongVu
Community Manager
Community Manager
December 9, 2022

I am not sure why you got those error. I check the line 217 in my SDK and it is an empty line. It looks like you still have the old SDK but not so sure about that.

What PHP version do you have in your local machine? Mine is 8.1.9.

I also built a no SDK engine to show how to access RingCentral platform using native PHP libs. Can you clone and try it.

The First Step
December 19, 2022

Thank you for your answer. It does work!.
However: I am trying to use a put function, like "update Extension".
Can you maybe enhance your ringcentral.php with a "put" function. Then it would be perfect.

I very much like the idea of "no SDK" and native PHP.

Once again thank you very much for your help.

PhongVu
Community Manager
Community Manager
December 19, 2022

Surely I can add other HTTP methods and improve the engine. However, I was expecting that when developers want to go for native PHP, they are PHP experts and want to code the engine the way they want to. With the demo engine, one does not need to start everything from scratch but they are free to change and update the engine for their app. Otherwise, I feel like I am implementing another SDK ;)

The First Step
January 12, 2023

updating my php version solved the issue. Thank you for your help.