Closed fpodshivadlov closed 2 years ago
The OrderCloud API returnes refresh_token
for portal auth and doesn't return it for organization auth.
As I can see the current portal-javascript-sdk
doesn't support custom refresh token logic.
Hopefully it can be done with the following workaround (changes for download.ts
operation):
var refreshPortalToken: string;
Replace: portalToken = (await portal.login(username, password)).access_token;
with:
const portalTokenData = await portal.login(username, password);
portalToken = portalTokenData.access_token;
refreshPortalToken = portalTokenData.refresh_token;
Add after Tokens.SetAccessToken(org_token);
async function refreshTokenFunc() {
console.log(`Requesting new token...`);
const portalTokenData = await portal.refreshToken(refreshPortalToken);
portalToken = portalTokenData.access_token;
org_token = await portal.getOrganizationToken(marketplaceID, portalToken);
Tokens.SetAccessToken(org_token);
}
setInterval(refreshTokenFunc, 10 * 60 * 1000); // interval is hardcoded
Hi @fpodshivadlov. Thanks for creating the issue!
I apologize for the slow reply. If you can make this PR I will confirm it works and publish it!
Otherwise I can make the PR myself but it might be a little while.
Should be fixed in version 1.0.30
The token issued by OrderCloud portal is valid only for 20 minutes, it's not enough for bigger marketplaces. So Refresh Token support is crucial for real world solutions.
The console output: