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
unable to use pwd or JWT authentication
Tags: authentication
Nov 30, 2022 at 7:39pm   •   11 replies  •  0 likes
Peter Hogger

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

on Nov 30, 2022 at 8:21pm   •  0 likes

my ClientID = kxHXJZJwRzW8W6EiwB_a5Q

10 Answers
answered on Jan 11, 2023 at 4:07pm  

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


 1
answered on Dec 19, 2022 at 8:21am  

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.


 0
on Dec 19, 2022 at 9:06am   •  0 likes

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

answered on Dec 9, 2022 at 8:13am  

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?


 0
on Dec 9, 2022 at 8:39am   •  0 likes

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.

answered on Dec 8, 2022 at 5:30pm  

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
}

 0
answered on Dec 8, 2022 at 3:47pm  

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


 0
answered on Dec 6, 2022 at 6:30pm  

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


 0
on Dec 6, 2022 at 8:44pm   •  0 likes

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

answered on Dec 5, 2022 at 11:47am  

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.


 0
answered on Dec 5, 2022 at 10:35am  

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.


 0
on Dec 5, 2022 at 10:59am   •  0 likes

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

answered on Dec 4, 2022 at 9:10am  

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?


 0
on Dec 5, 2022 at 8:44am   •  0 likes

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.

answered on Nov 30, 2022 at 8:21pm  

my ClientID = kxHXJZJwRzW8W6EiwB_a5Q


 0
answered on Dec 1, 2022 at 7:43am  

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.


 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