Refresh token is missing error - Does it need periodic re-login to work?
ElridgeDMello opened this issue · 1 comments
We have a node process that on startup executes the following initRingCentralSDK
function which creates an instance of the RC SDK and logs in (using password workflow).
let rcsdk;
export function initRingCentralSDK(done) {
rcsdk = new SDK({
server: SDK.server[process.env.RC_ENVIRONMENT || 'sandbox'],
appKey: process.env.RC_APP_KEY,
appSecret: process.env.RC_APP_SECRET,
});
rcsdk.platform()
.login({
username: process.env.RC_USERNAME, // phone number in full format
extension: process.env.RC_EXTENSION, // leave blank if direct number is used
password: process.env.RC_PASSWORD,
})
.then(() => done(null, rcsdk))
.catch(e => done(e));
}
export function getRCSDKInstance(callback) {
if (rcsdk) {
process.nextTick(() => callback(null, rcsdk));
} else {
initRingCentralSDK(callback);
}
}
The initialized/logged in SDK instance is used elsewhere in the app to perform operations such as getting the list of extensions, and call logs using the function shown below:
function rcsdkCall({ method = 'GET', url, query = {} }, callback) {
getRCSDKInstance((err, rcsdk) => {
if (err) {
return callback(err);
}
rcsdk.platform()
.send({
method,
url,
query,
})
.then((apiResponse) => {
callback(null, apiResponse.json());
})
.catch((e) => {
callback(e);
});
});
}
However, after a while (e.g. days) of running successfully, we start getting "Refresh token is missing" errors on the rcsdk.platform().send({...})
calls.
I understood from the docs that the SDK "will refresh tokens for you automatically". Is there something we need to do to manually update the Refresh token?
SDK does all refreshes for you. Please write a ticket to devsupport@ringcentral.com with more info (headers, etc.) of the refresh error, so that our team can identify the root cause of it.
I also suggest to convert getRCSDKInstance to a promise and always use all SDK-related things as promises:
export function getRCSDKInstance(callback) {
if (rcsdk) {
return Promise.resolve(rcsdk);
} else {
return initRingCentralSDK();
}
}
// elsewhere
getRCSDKInstance().then((sdk) => sdk.platform().get(...)).then(...)