Skip to main content
Question

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.



3 replies

PhongVu
Community Manager
Forum|alt.badge.img
  • Community Manager
  • 2340 replies
  • October 9, 2023

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

  • Author
  • Participating Frequently
  • 7 replies
  • October 9, 2023

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": ""
}

PhongVu
Community Manager
Forum|alt.badge.img
  • Community Manager
  • 2340 replies
  • October 9, 2023

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.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings