question

Peter Hogger avatar image
Peter Hogger asked Peter Hogger answered

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".

authentication
1 comment
1 |3000

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

Peter Hogger avatar image Peter Hogger commented ·

my ClientID = kxHXJZJwRzW8W6EiwB_a5Q

0 Likes 0 ·
Phong Vu avatar image
Phong Vu answered

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.

1 |3000

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

Peter Hogger avatar image
Peter Hogger answered Phong Vu commented

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 RingCentral\SDK\SDK(_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): RingCentral\SDK\Http\Client->send(Object(GuzzleHttp\Psr7\Request))

#1 /app/www/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(465): RingCentral\SDK\Platform\Platform->sendRequest(Object(GuzzleHttp\Psr7\Request), Array)

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

#3 /app/www/rc_test.php(8): RingCentral\SDK\Platform\Platform->login(Array)

#4 {main}


Next RingCentral\SDK\Http\ApiException: 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): RingCentral\SDK\Http\Client->send(Object(GuzzleHttp\Psr7\Request))

#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?

1 comment
1 |3000

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

Phong Vu avatar image Phong Vu ♦♦ commented ·

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.

0 Likes 0 ·
Peter Hogger avatar image
Peter Hogger answered Phong Vu commented

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.

1 comment
1 |3000

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

Phong Vu avatar image Phong Vu ♦♦ commented ·

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

0 Likes 0 ·
Peter Hogger avatar image
Peter Hogger answered

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.


1 |3000

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

Peter Hogger avatar image
Peter Hogger answered Phong Vu commented

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

1 comment
1 |3000

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

Phong Vu avatar image Phong Vu ♦♦ commented ·

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

0 Likes 0 ·
Peter Hogger avatar image
Peter Hogger answered

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


1 |3000

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

Phong Vu avatar image
Phong Vu answered

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 RingCentral\SDK\SDK($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 (\RingCentral\SDK\Http\ApiException $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
}
1 |3000

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

Peter Hogger avatar image
Peter Hogger answered Phong Vu commented

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?

1 comment
1 |3000

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

Phong Vu avatar image Phong Vu ♦♦ commented ·

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.

0 Likes 0 ·
Peter Hogger avatar image
Peter Hogger answered Phong Vu commented

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.

1 comment
1 |3000

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

Phong Vu avatar image Phong Vu ♦♦ commented ·

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

0 Likes 0 ·
Peter Hogger avatar image
Peter Hogger answered

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

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