OAuth authentication API

  • 1
  • Question
  • Updated 9 months ago
  • Answered
Hey, I am trying to get the access token and refresh token. I am sending the request using curl. I have followed all the steps written in API docs. The response I am getting is 

{

  "error" : "invalid_grant",

  "error_description" : "Invalid resource owner credentials."

}

Can u tell me what's wrong with that ????

Thank You!!!
Photo of Sumit Agarwal

Sumit Agarwal

  • 150 Points 100 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Claudio (Customer)

Claudio (Customer)

  • 118 Points 100 badge 2x thumb
"invalid_grant
The provided authorization grant (e.g., authorization
code, resource owner credentials) or refresh token is
invalid, expired, revoked, does not match the redirection
URI used in the authorization request, or was issued to
another client.
"

I found this document, hope it helps:

http://oauthlib.readthedocs.org/en/la...
(Edited)
Photo of VB

VB, Official Rep

  • 1,410 Points 1k badge 2x thumb

This error indicates that the user credentials provided are improper, e.g. username, extension, and/or password.

Below is information on getting your proper credentials in the Sandbox Environment and Production Environment.

1) Sandbox Environment User Credentials

If you are on Sandbox Environment,  follow the below steps to get your sandbox account credentials:

  1. Login to https://developer.ringcentral.com/ using your Developer Platform credentials (RC account credentials)
  2. Go to your Sandbox Account page: "My Account > Sandbox Account". Locate the "Main Company Number" which will be your username when formatted in E.164 format, (example: +12223334444).  
  3. The password is the password you received via email when you created the sandbox account, unless you have changed the password.
The above credentials can also be used for logging into, and reset at, the Online Account Portal for Sandbox Environment at: https://service.devtest.ringcentral.com/

In addition to your user credentials, you need to ensure you are connecting to the correct Sandbox API end point and using the correct application credentials described below:
  1. For sandbox environment, the API sever end endpoint URI is  https://platform.devtest.ringcentral.com 
  2. Find your application key and secret by clicking on My Account -> Applications -> Application Name. Use Sandbox Application key and secrets

The easiest way to start testing our APIs would be by using our  API Explore here  http://ringcentral.github.io/api-explorer/. You can start filling out your RC sandbox credentials and start going from there. We have self explanatory documentation in the link above.

2) Production Environment

If you are on Production Environment, follow the below steps to get your production account credentials:

  1. The user credentials for production are the same ones as for your RingCentral phone account that you use, e.g. to log into the Online Account Portal at https://service.ringcentral.com.
In addition to your user credentials, you need to ensure you are connecting to the correct Production API end point and using the correct application credentials described below:
  1. For production environment, the sever end endpoint uri is  https://platform.ringcentral.com 
  2. Find your application key and secret by clicking on My Account -> Applications -> Application Name. Use Production Application key and secrets

For more information please visit this link: https://developer.ringcentral.com/library/tutorials/test-account.html

(Edited)
Photo of Sumit Agarwal

Sumit Agarwal

  • 150 Points 100 badge 2x thumb
Hey VB,

Thanks for the reply. I have got the acces token. Now, I am trying to make a ringout call using the ringcentral API. The request body I am passing is like this :

{  "to": {"phoneNumber": "91*******"},
  "from": {"phoneNumber": "91*******"},
  "callerId": {"phoneNumber": "91*******"},
  "playPrompt": true
}

The response I am getting is : 

{ "message": "Forbidden", "errorCode": "InternationalProhibited" }

The same call when I try to make with the ringcentral account is successful. Can u tell me what's wrong with that. 
Photo of Naveen Sanjeeva

Naveen Sanjeeva, Official Rep

  • 60 Points
International calling is not supported in the Sandbox. Please use US local numbers or numbers on your test account to place calls to verify your code. This will work as expected in Production provided the accounts you use there have the right privileges and credits to make international calls.
(Edited)
Photo of Andrei T

Andrei T

  • 80 Points 75 badge 2x thumb
Hi - i do provide all the correct information, but still get this error. what could i possibly be doing wrong? this is a sandbox account
Photo of Andrei T

Andrei T

  • 80 Points 75 badge 2x thumb
On top of that, i am unable to login with my 'main' account number auto-generated when i opened up a sandbox account.

https://service.devtest.ringcentral.com/#/number

but it works with the email option
Photo of Andrei T

Andrei T

  • 80 Points 75 badge 2x thumb
It stops working the moment i switch the app type to 'server only'
Photo of VB

VB, Official Rep

  • 1,410 Points 1k badge 2x thumb
Can you send us a mail at devsupport@ringcentral.com
Photo of sushil kumar

sushil kumar

  • 120 Points 100 badge 2x thumb
Hello,

I want to use Ringcentral Ringout call in my app. I follow https://developer.ringcentral.com/api-explorer/latest/index.html#/RingOut 

But, I am unable to login through CURL. Please assist how can I login through CURL
Photo of AK

AK, Official Rep

  • 4,382 Points 4k badge 2x thumb
Hi Sushil,

Before you login, could you please check if the Application type = Private and Platform Type = Server-only ( NO UI ). 

As all other application types would need Authorization Code Flow or commonly known as OAuth2.0 as the authentication flow. However, if your application is of the above mentioned type then you can use the Password Flow as the authentication flow.

However, I would recommend you take a look at our dev community article below on how to login ( get tokens ) through cURL:
https://devcommunity.ringcentral.com/ringcentraldev/topics/curl-command-for-requesting-access-token
Photo of sushil kumar

sushil kumar

  • 120 Points 100 badge 2x thumb
Hello AK,

Thanks for your reply!

I tried, followed by https://devcommunity.ringcentral.com/ringcentraldev/topics/curl-command-for-requesting-access-token . However, I got
{
  "error" : "invalid_request",
  "error_description" : "Unsupported grant type" 
}

Please help me out this.
Photo of AK

AK, Official Rep

  • 4,382 Points 4k badge 2x thumb
Can you provide the name of your app on Developer portal?

Additionally, you can take a look at this community article where another developer faced a similar issue and they were able to fix the issue. 
https://devcommunity.ringcentral.com/ringcentraldev/topics/unauthorized-for-this-grant-type-error
Photo of sushil kumar

sushil kumar

  • 120 Points 100 badge 2x thumb
Hello AK,

My developer app name is  Sushil. what is the difference between grant_type password and login password.

I am stuck on this. Please help me out.

Thanks
Photo of sushil kumar

sushil kumar

  • 120 Points 100 badge 2x thumb
I am using CURL PHP. Here is the code.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://platform.devtest.ringcentral.com/restapi/oauth/token;");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=+19045591288&password=XXXXX&extension=101&grant_type=XXXXX");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "XXXXXXw0H8R2mUjiky28mElw" . ":" . "vOh9QIsYQRScrVRGn-GF9ACY-izpBITMC7SN8jjXXXXX");

$headers = array();
$headers[] = "Accept: application/json";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
   echo 'Error:' . curl_error($ch);
}

echo '<pre>';
print_r($result);
curl_close ($ch);

I want to make call using Ringout. I follow https://developer.ringcentral.com/api-explorer/latest/index.html#/RingOut 

When I make Authorize and Ringout Call then I got "Inprogress" status. I want to implement it in my custom code. However, I need "access_token", so I tried above script for login and get access_token. But I get error.

Kindly check and help me out.

Thanks :)
Photo of sushil kumar

sushil kumar

  • 120 Points 100 badge 2x thumb
Hello Ak,

Hope you understand my requirement. I am still waiting for your positive response.

Thanks
Photo of sushil kumar

sushil kumar

  • 120 Points 100 badge 2x thumb
Hello AK,

I used below links to implement Ringout outbound process:

PHP – SDK : https://github.com/ringcentral/ringcentral-php 

Oauth Demo ( for getting accessTokens ) : https://github.com/ringcentral/ringcentral-demos-oauth/tree/master/php

However, I got the below response: 

{ "uri" : "https://platform.devtest.ringcentral.com/restapi/v1.0/account/217638004/extension/217638004/ring-out...;, "id" : "Y3MxNjk2MTIzOTgxMzEyMTM2OTZAMTAuMjguMjAuMTEw", "status" : { "callStatus" : "InProgress", "callerStatus" : "InProgress", "calleeStatus" : "InProgress" } }


Kindly assist me for the next step to make a call. Thanks in advance.