( config: ProConfig, authRes: AuthResError | AuthResSucc, saveUpdatedConfigFunc: () => Promise<any> | undefined )
| 107 | } |
| 108 | |
| 109 | export const setConfigBySuccessfullAuthInplace = async ( |
| 110 | config: ProConfig, |
| 111 | authRes: AuthResError | AuthResSucc, |
| 112 | saveUpdatedConfigFunc: () => Promise<any> | undefined |
| 113 | ) => { |
| 114 | if (authRes.error !== undefined) { |
| 115 | throw Error( |
| 116 | `remotely save account auth failed, please auth again: ${authRes.error}` |
| 117 | ); |
| 118 | } |
| 119 | |
| 120 | config.accessToken = authRes.access_token; |
| 121 | config.accessTokenExpiresAtTimeMs = |
| 122 | Date.now() + authRes.expires_in * 1000 - 5 * 60 * 1000; |
| 123 | config.accessTokenExpiresInMs = authRes.expires_in * 1000; |
| 124 | config.refreshToken = authRes.refresh_token || config.refreshToken; |
| 125 | |
| 126 | // manually set it expired after 80 days; |
| 127 | config.credentialsShouldBeDeletedAtTimeMs = |
| 128 | Date.now() + OAUTH2_FORCE_EXPIRE_MILLISECONDS; |
| 129 | |
| 130 | await saveUpdatedConfigFunc?.(); |
| 131 | |
| 132 | console.info( |
| 133 | "finish updating local info of Remotely Save official website token" |
| 134 | ); |
| 135 | }; |
| 136 | |
| 137 | export const getAccessToken = async ( |
| 138 | config: ProConfig, |
no outgoing calls
no test coverage detected