question

Nirmal Babu avatar image
Nirmal Babu asked Nirmal Babu edited

Invalid resource owner credentials when using access token

Getting Invalid resource owner credentials error regularly after some time when using acesss tokens to authorize ringcentral user. We are getting the access tokens by authorizing using grant_type=password. And are reusing the same access tokens for the next 1 hr to make API calls and then re generate tokens.


Using ringcentral java SDK version 1.4.0

We are facing this with ringcentral production credentials

@Phong Vu could you please help in finding the root cause?

credentials
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 Nirmal Babu edited

So when it fails, it fails in this loop, right?

if(token == null or createdTime> 60mins){
    TokenInfo ti = restClient.authorize(rcId, ext, password);
    ...

There is a reason to double check (at least print it to the console so you can see it) if rcId, ext and password are the same as when you first login.

I don't know how you save the token into a db and what is the primary key. The name "rcId" sound like an account Id rather than a username to me.

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 Nirmal Babu commented

When you get such an error, you need to trust the error message. There are many possible mistakes that cause the problem.

static String RINGCENTRAL_CLIENT_ID_PROD = "production app client id";
static String RINGCENTRAL_CLIENT_SECRET_PROD = "production app client secret";
static String RINGCENTRAL_SERVER_PROD = "https://platform.ringcentral.com";

static String RINGCENTRAL_USERNAME_PROD = "some production username";
static String RINGCENTRAL_PASSWORD_PROD = "some production user password";
static String RINGCENTRAL_EXTENSION_PROD = "some production user extension number";

static String RINGCENTRAL_CLIENT_ID_SANDBOX = "sandbox app client id";
static String RINGCENTRAL_CLIENT_SECRET_SANDBOX = "sandbox app client secret";
static String RINGCENTRAL_SERVER_SANDBOX = "https://platform.devtest.ringcentral.com";

static String RINGCENTRAL_USERNAME_SANDBOX = "some sandbox username";
static String RINGCENTRAL_PASSWORD_SANDBOX = "some sandbox user password";
static String RINGCENTRAL_EXTENSION_SANDBOX = "some sandbox user extension number";

static RestClient restClient;


public static void main(String[] args){
  try {
    restClient = new RestClient(RINGCENTRAL_CLIENT_ID_PROD, RINGCENTRAL_CLIENT_SECRET_PROD, RINGCENTRAL_SERVER_PROD);
    restClient.authorize(RINGCENTRAL_USERNAME_PROD, RINGCENTRAL_EXTENSION_PROD, RINGCENTRAL_PASSWORD_PROD);
...

If you mix any of the parameters between the production and sandbox, you would end up in such an error. Many developers make such a mistake when they don't change the username, password and extension number properly.

Double check, try again and let me know

3 comments
1 |3000

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

Nirmal Babu avatar image Nirmal Babu commented ·

Hi @Phong Vu we are using correct parameters only

The issue is, it is working for some time later on it throws invalid resource credentials error and after some time again it works fine.

Earlier we used to authorize every single time to send an SMS, didnt have any issues then except for the rate limit exceeded

Only change is now, we are using access tokens and are reusing them(until they expire which is for 1 hr and regenerate again) to authorize and then send SMS.

0 Likes 0 ·
Yatin Gera avatar image Yatin Gera ♦♦ Nirmal Babu commented ·

Hi @Nirmal Babu
Could you please share your code here so that we can see what is happening?

0 Likes 0 ·
Nirmal Babu avatar image Nirmal Babu Yatin Gera ♦♦ commented ·

Hi @Yatin Gera

RestClient restClient = new RestClient(clientId,clientSecret, server);

token = getAccessToken from DB - for rcId

if(token == null or createdTime> 60mins) {

    TokenInfo ti = restClient.authorize(rcId, ext, password);

    save -> token = ti.access_token

    save -> createdTime = Calendar.getInstance().getTime()

}

else{

    TokenInfo ti = new TokenInfo();

    ti.access_token(token);

    restClient.token = ti;

}


0 Likes 0 ·

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