diff options
author | bobzel <zzzman@gmail.com> | 2025-06-04 22:07:36 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2025-06-04 22:07:36 -0400 |
commit | 59689fe94c27986674dd6ecb7f0e6073861a98a6 (patch) | |
tree | 42ef1d5a631676e0b0c63076f60a48064fac642d /src | |
parent | f7cb0dcebb0514cf38f8a7e635ec9959c196145a (diff) |
more cleanup of google authorization
Diffstat (limited to 'src')
-rw-r--r-- | src/server/ApiManagers/GeneralGoogleManager.ts | 12 | ||||
-rw-r--r-- | src/server/apis/google/GoogleApiServerUtils.ts | 7 | ||||
-rw-r--r-- | src/server/authentication/DashUserModel.ts | 6 |
3 files changed, 4 insertions, 21 deletions
diff --git a/src/server/ApiManagers/GeneralGoogleManager.ts b/src/server/ApiManagers/GeneralGoogleManager.ts index 693b17779..7581eec13 100644 --- a/src/server/ApiManagers/GeneralGoogleManager.ts +++ b/src/server/ApiManagers/GeneralGoogleManager.ts @@ -99,17 +99,7 @@ export default class GeneralGoogleManager extends ApiManager { secureHandler: async ({ user, req, res }) => new Promise<void>(resolve => GoogleApiServerUtils.processNewUser(user.id, req.query.code as string) - .then(enriched => { - if (enriched.refresh_token) { - if (enriched.refresh_token) { - user.googleToken = enriched.refresh_token; - user.save(); - } else { - console.warn('No refresh token returned'); - } - } - res.status(200).send('Google account linked successfully!'); - }) + .then(() => res.status(200).send('Google account linked successfully!')) .catch(err => { console.error('Failed to process Google code:', err); res.status(500).send('Error linking Google account'); diff --git a/src/server/apis/google/GoogleApiServerUtils.ts b/src/server/apis/google/GoogleApiServerUtils.ts index 45c661730..24905896d 100644 --- a/src/server/apis/google/GoogleApiServerUtils.ts +++ b/src/server/apis/google/GoogleApiServerUtils.ts @@ -14,7 +14,6 @@ import { DashUserModel } from '../../authentication/DashUserModel'; * This is the somewhat overkill list of what Dash requests * from the user. */ -// 'https://www.googleapis.com/auth/tasks', 'openid', 'profile' const scope = ['tasks', 'documents.readonly', 'documents', 'presentations', 'presentations.readonly', 'drive', 'drive.file', 'photoslibrary', 'photoslibrary.appendonly', 'photoslibrary.sharing', 'userinfo.profile'].map( relative => `https://www.googleapis.com/auth/${relative}` ); @@ -122,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; } @@ -299,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', @@ -308,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); diff --git a/src/server/authentication/DashUserModel.ts b/src/server/authentication/DashUserModel.ts index 4397e2bd4..debeef60c 100644 --- a/src/server/authentication/DashUserModel.ts +++ b/src/server/authentication/DashUserModel.ts @@ -9,14 +9,9 @@ export type DashUserModel = mongoose.Document & { passwordResetToken?: string; passwordResetExpires?: Date; - - // AARAV ADD - googleToken?: string; - dropboxRefresh?: string; dropboxToken?: string; - userDocumentId: string; sharingDocumentId: string; linkDatabaseId: string; @@ -45,7 +40,6 @@ const userSchema = new mongoose.Schema( passwordResetToken: String, passwordResetExpires: Date, - googleToken: String, dropboxRefresh: String, dropboxToken: String, userDocumentId: String, // id that identifies a document which hosts all of a user's account data |