| 322 | }; |
| 323 | |
| 324 | export const setConfigBySuccessfullAuthInplace = async ( |
| 325 | config: DropboxConfig, |
| 326 | authRes: DropboxSuccessAuthRes, |
| 327 | saveUpdatedConfigFunc: () => Promise<any> | undefined |
| 328 | ) => { |
| 329 | console.info("start updating local info of Dropbox token"); |
| 330 | |
| 331 | config.accessToken = authRes.access_token; |
| 332 | config.accessTokenExpiresInSeconds = Number.parseInt(authRes.expires_in); |
| 333 | config.accessTokenExpiresAtTime = |
| 334 | Date.now() + Number.parseInt(authRes.expires_in) * 1000 - 10 * 1000; |
| 335 | |
| 336 | // manually set it expired after 80 days; |
| 337 | config.credentialsShouldBeDeletedAtTime = |
| 338 | Date.now() + OAUTH2_FORCE_EXPIRE_MILLISECONDS; |
| 339 | |
| 340 | if (authRes.refresh_token !== undefined) { |
| 341 | config.refreshToken = authRes.refresh_token; |
| 342 | config.accountID = authRes.account_id!; |
| 343 | } |
| 344 | |
| 345 | if (saveUpdatedConfigFunc !== undefined) { |
| 346 | await saveUpdatedConfigFunc(); |
| 347 | } |
| 348 | |
| 349 | console.info("finish updating local info of Dropbox token"); |
| 350 | }; |
| 351 | |
| 352 | //////////////////////////////////////////////////////////////////////////////// |
| 353 | // real exported interface |