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.
Thanks for your answer!
Yes, I do have support for `Issue refresh tokens`
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": "" }
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.
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.
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.
Thanks!
Login your RingCentral developer portal and check the app auth type and if you set it to support refresh token or not.
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()
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