aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/server/ApiManagers/GeneralGoogleManager.ts12
-rw-r--r--src/server/apis/google/GoogleApiServerUtils.ts7
-rw-r--r--src/server/authentication/DashUserModel.ts6
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