diff options
author | Skitty1238 <157652284+Skitty1238@users.noreply.github.com> | 2025-06-04 22:30:11 -0400 |
---|---|---|
committer | Skitty1238 <157652284+Skitty1238@users.noreply.github.com> | 2025-06-04 22:30:11 -0400 |
commit | 745784b36e0f6fd2557ffe0d32cf11051627b148 (patch) | |
tree | afb4a23fdb801660b0017c6faefe50ac9e7a6531 /src/server/apis/google/GoogleApiServerUtils.ts | |
parent | eb9c93a635191ef9ec842592c4a85262811cf108 (diff) | |
parent | 488451f04d42642f11975e9532542a78622b16ef (diff) |
Merge branch 'task_nodes_aarav' of https://github.com/brown-dash/Dash-Web into task_nodes_aarav
Diffstat (limited to 'src/server/apis/google/GoogleApiServerUtils.ts')
-rw-r--r-- | src/server/apis/google/GoogleApiServerUtils.ts | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/src/server/apis/google/GoogleApiServerUtils.ts b/src/server/apis/google/GoogleApiServerUtils.ts index 56bc79119..24905896d 100644 --- a/src/server/apis/google/GoogleApiServerUtils.ts +++ b/src/server/apis/google/GoogleApiServerUtils.ts @@ -121,8 +121,7 @@ export namespace GoogleApiServerUtils { * @returns the relevant 'googleapis' wrapper, if any */ export async function GetEndpoint(sector: string, user: DashUserModel): Promise<Endpoint | void> { - if (!user.googleToken) await retrieveOAuthClient(user); - const auth = user.googleToken; // await retrieveOAuthClient(user); + const auth = await retrieveOAuthClient(user); if (!auth) { return; } @@ -184,21 +183,7 @@ export namespace GoogleApiServerUtils { * @returns the newly generated url to the authentication landing page */ export function generateAuthenticationUrl(): string { - const oauth2Client = new google.auth.OAuth2( - '838617994486-a28072lirm8uk8cm78t7ic4krp0rgkgv.apps.googleusercontent.com', - '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', - 'http://localhost:1050/refreshGoogle' // Ensure this matches the redirect URI in Google Cloud Console - ); - - return oauth2Client.generateAuthUrl({ - access_type: 'offline', - scope: [ - 'https://www.googleapis.com/auth/tasks', - 'openid', - 'profile' - ], - prompt: 'consent', // This ensures we get a refresh token - }); + return worker.generateAuthUrl({ scope, access_type: 'offline', prompt: 'consent' }); } /** @@ -220,12 +205,12 @@ export namespace GoogleApiServerUtils { */ export async function processNewUser(userId: string, authenticationCode: string): Promise<EnrichedCredentials> { const credentials = await new Promise<Credentials>((resolve, reject) => { - worker.getToken(authenticationCode, (err, credentials) => { - if (err || !credentials) { + worker.getToken(authenticationCode, (err, creds) => { + if (err || !creds) { reject(err); return; } - resolve(credentials); + resolve(creds); }); }); const enriched = injectUserInfo(credentials); @@ -312,7 +297,7 @@ export namespace GoogleApiServerUtils { const headerParameters = { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }; const { client_id, client_secret } = GoogleCredentialsLoader.ProjectCredentials; const params = new URLSearchParams({ - refresh_token: credentials.refresh_token!, // AARAV use user.googleToken + refresh_token: credentials.refresh_token!, client_id, client_secret, grant_type: 'refresh_token', @@ -321,6 +306,7 @@ export namespace GoogleApiServerUtils { const { access_token, expires_in } = await new Promise<{ access_token: string; expires_in: number }>(resolve => { request.post(url, headerParameters).then(response => resolve(JSON.parse(response))); }); + // expires_in is in seconds, but we're building the new expiry date in milliseconds const expiry_date = new Date().getTime() + expires_in * 1000; await Database.Auxiliary.GoogleAccessToken.Update(user.id, access_token, expiry_date); |