MCPcopy
hub / github.com/remotely-save/remotely-save / setConfigBySuccessfullAuthInplace

Function setConfigBySuccessfullAuthInplace

pro/src/account.ts:109–135  ·  view source on GitHub ↗
(
  config: ProConfig,
  authRes: AuthResError | AuthResSucc,
  saveUpdatedConfigFunc: () => Promise<any> | undefined
)

Source from the content-addressed store, hash-verified

107}
108
109export 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
137export const getAccessToken = async (
138 config: ProConfig,

Callers 2

onOpenMethod · 0.90
getAccessTokenFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected