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
Refresh token is missing
Tags: sdk, authentication
Oct 9, 2023 at 7:05am   •   2 replies  •  0 likes
Roman Pierce

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.



2 Answers
answered on Oct 9, 2023 at 9:22am  

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

 0
on Oct 9, 2023 at 10:38am   •  1 likes

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.

on Oct 9, 2023 at 12:21pm   •  0 likes

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.




on Oct 9, 2023 at 12:32pm   •  1 likes

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.

on Oct 10, 2023 at 8:45am   •  0 likes

Thanks!

answered on Oct 9, 2023 at 9:01am  

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



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