question

Roman Pierce avatar image
Roman Pierce asked Roman Pierce commented

Refresh token is missing

Hello. We are using JWT authorization for the application.


We use official js SDK https://github.com/ringcentral/ringcentral-js

Here is what my authorization looks like:

    const rcSdk = new SDK({
      server: SDK.server[environment],
      clientId,
      clientSecret
    });


    this.platform = rcSdk.platform();


   await this.platform.login({ jwt: this.jwt });


After that, we are working with different API, for example

  public async ringOut(from: string, to: string): Promise<RingOutResponse> {
    const response = await this.platform.post('/restapi/v1.0/account/~/extension/~/ring-out', {
      from: { phoneNumber: from },
      to: { phoneNumber: to },
      playPrompt: false,
    });


    return response.json() as Promise<RingOutResponse>;
  }


  public async searchAccountsByEmail(email: string): Promise<DirectorySearchResponse> {
    const response = await this.platform.post(`/restapi/v1.0/account/~/directory/entries/search`, {
      searchString: email,
    });


    return response.json() as Promise<DirectorySearchResponse>;
  }


  public async getCallLogs(telephonySessionId: string): Promise<GetCallLogsResponse> {
    const response = await this.platform.get(`/restapi/v1.0/account/~/call-log`, {
      telephonySessionId,
    });


    return response.json() as Promise<GetCallLogsResponse>;
  }


But after some time (it could be an hour, it could be 20+ hours, I don't know the pattern for sure) we receive an error while calling an API Refresh token is missing


It happens too often and it really disrupts our work.


Could you please help us?


Thanks.



sdkauthentication
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

Login your RingCentral developer portal and check the app auth type and if you set it to support refresh token or not.

3983-screen-shot-2023-01-09-at-91654-am.png

If the option was selected and you still face the problem. Can you read the tokens and print it to the console when you receive the error. Then check the tokens to see if the refresh_token exists.

var tokens = await this.platform.auth().data()

1 |3000

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

Roman Pierce avatar image
Roman Pierce answered Roman Pierce commented

Thanks for your answer!

Yes, I do have support for `Issue refresh tokens`

1696867744797.png


And `refresh_token` is exist in await this.platform.auth().data()

{
  "token_type": "bearer",
  "access_token": "U0pDMDFQMTdQQVMwMHxBQUFCd2p3TnpYeFVo...",
  "expire_time": 1696871949101,
  "expires_in": 3600,
  "refresh_token": "U0pDMDFQMTdQQVMwMHxBQURYTk14OHpz...",
  "refresh_token_expires_in": 604800,
  "refresh_token_expire_time": 1697473149101,
  "scope": "CallControl ReadAccounts RingOut ReadCallLog ReadCallRecording SubscriptionWebhook",
  "owner_id": "11111",
  "endpoint_id": "OjFk12313131",
  "code_verifier": ""
}

1696867744797.png (228.2 KiB)
4 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.

Phong Vu avatar image Phong Vu ♦♦ commented ·

I suggest you to add this code to your project to deal with the issue. (modify the code you fit in your class function)

async function login_jwt(){
    try{
      var resp = await this.platform.login({ jwt: "XXXXXXX" } )
      return true
    }catch(e) {
      return false
    }
}

async function tokensValid(){
    var ret = await this.platform.loggedIn()
    if (!ret) {
       console.log("BOTH TOKEN TOKENS EXPIRED => USE JWT")
       ret = await login_jwt(); // Call your login function to login again using the JWT token
       ret = true
    }
    return ret
}

...

if (await tokensValid()){ 
    // Call function that call RingCentral APIs
    ...
} 


Please keep track of the time it forces you to call the login_jwt function to re-authenticate. If that is very often (refresh token should be valid for 7 days if your app is idle or does not call any RC API using the SDK) then submit a support ticket so someone can investigate the issue for you.

1 Like 1 ·
Roman Pierce avatar image Roman Pierce Phong Vu ♦♦ commented ·

Thanks for the suggestion!

Please keep track of the time it forces you to call the login_jwt function to re-authenticate. If that is very often (refresh token should be valid for 7 days if your app is idle or does not call any RC API using the SDK) then submit a support ticket so someone can investigate the issue for you.

I would say even if I have like "rare" cases when my tokens because outdated/removed it still looks incorrect to me.




0 Likes 0 ·
Phong Vu avatar image Phong Vu ♦♦ Roman Pierce commented ·

I will try to reproduce the problem myself too. But if you also keep track of the problem and if you catch it more often, then it would help me better finding the root cause.

1 Like 1 ·
Show more comments

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