Skip to main content

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

my ClientID = kxHXJZJwRzW8W6EiwB_a5Q


You cannot use password flow authentication for this app because you chose the JWT auth type. I enabled the password flow type for you to test.

Now you should be able to login using either JWT or username and password of user extensions under your sandbox account. Please let me know if you still cannot login with your JWT token, and if you don't want to use the password flow so I can change it back.


I am now able to log in via pwd, which is a big step forward. Thank you!

I would however additionally like to use JWT, which still is giving me the "Unauthorized for this grant type",

My php statement reads:

$rcsdk = new RingCentralSDKSDK(_CLIENTID, _CLIENTSECRET, _SERVER);

$platform = $rcsdk->platform();

$platform->login( array( 'jwt' => _JWT));


and the error message is:


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

PHP Fatal error: Uncaught Exception: Response has unsuccessful status in /app/www/vendor/ringcentral/ringcentral-php/src/Http/Client.php:44

Stack trace:

#0 /app/www/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(329): RingCentralSDKHttpClient->send(Object(GuzzleHttpPsr7Request))

#1 /app/www/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(465): RingCentralSDKPlatformPlatform->sendRequest(Object(GuzzleHttpPsr7Request), Array)

#2 /app/www/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(221): RingCentralSDKPlatformPlatform->requestToken('/restapi/oauth/...', Array)

#3 /app/www/rc_test.php(8): RingCentralSDKPlatformPlatform->login(Array)

#4 {main}


Next RingCentralSDKHttpApiException: Unauthorized for this grant type in /app/www/vendor/ringcentral/ringcentral-php/src/Http/Client.php:52

Stack trace:

#0 /app/www/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(329): RingCentralSDKHttpClient->send(Object(GuzzleHttpPsr7Request))

#1 /app/www/vendor/ringcentral/ in /app/www/vendor/ringcentral/ringcentral-php/src/Http/Client.php on line 52


Can you enable PWD (clientID: J2W7_NM5S46rnmS76HptSw) and JWT (clientID : kxHXJZJwRzW8W6EiwB_a5Q) at the same time?


This app (J2W7_NM5S46rnmS76HptSw) is currently set password flow. Do you want to enable JWT?

And this app (kxHXJZJwRzW8W6EiwB_a5Q) is set both password flow and JWT token as I set it for you last time.

And for the error. When did you update/install the RingCentral PHP SDK? Make sure to get the latest version which support JWT tokens.


I am trying to test, but cannot create another JWT Token as I am receiving the error:
You have reached your limit of available sandbox logins. To increase this limit, please file a ticket with support.


What did you do when you got that error? Generate a new JWT token?


2022-12-05-14-45-46-window.png2022-12-05-14-46-16-window.pngwhen I go to <my Name>, Credentials -> create JWT (as I don't have one) -> the sandbox option is greyed out.. and I have a pop up with:You need an account in the sandbox environment to select this option. Create login credential
which then brings me the error: You have reached your limit of available sandbox logins. To increase this limit, please file a ticket with support.


Dear Dev Support

I am now able to create JWT token, but it seems that the CLIENTID = 'kxHXJZJwRzW8W6EiwB_a5Q' is still no set for JWT authentication. Can you please verify.

I even re-installed the PHP SDK with: (no change)

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

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


Your app auth type is JWT auth. Can I revoke the JWT token and regenerate a new one to test on your behalf?


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


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
}

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?


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.


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.


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 ;)


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


Reply