diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/ApiManagers/GeneralGoogleManager.ts | 39 | ||||
-rw-r--r-- | src/server/apis/google/GoogleApiServerUtils.ts | 13 |
2 files changed, 22 insertions, 30 deletions
diff --git a/src/server/ApiManagers/GeneralGoogleManager.ts b/src/server/ApiManagers/GeneralGoogleManager.ts index 59d066934..693b17779 100644 --- a/src/server/ApiManagers/GeneralGoogleManager.ts +++ b/src/server/ApiManagers/GeneralGoogleManager.ts @@ -96,25 +96,26 @@ export default class GeneralGoogleManager extends ApiManager { register({ method: Method.GET, subscription: '/refreshGoogle', - secureHandler: async ({ user, req, res }) => { - const code = req.query.code as string; - - try { - const enriched = await GoogleApiServerUtils.processNewUser(user.id, code); - - if (enriched.refresh_token) { - if (enriched.refresh_token) { - user.googleToken = enriched.refresh_token; - await user.save(); - } else { - console.warn('No refresh token returned'); - } - } - } catch (err) { - console.error('Failed to process Google code:', err); - res.status(500).send('Error linking Google account'); - } - }, + 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!'); + }) + .catch(err => { + console.error('Failed to process Google code:', err); + res.status(500).send('Error linking Google account'); + }) + .finally(resolve) + ), }); } } diff --git a/src/server/apis/google/GoogleApiServerUtils.ts b/src/server/apis/google/GoogleApiServerUtils.ts index 2f7ef473c..45c661730 100644 --- a/src/server/apis/google/GoogleApiServerUtils.ts +++ b/src/server/apis/google/GoogleApiServerUtils.ts @@ -14,6 +14,7 @@ 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}` ); @@ -184,17 +185,7 @@ export namespace GoogleApiServerUtils { * @returns the newly generated url to the authentication landing page */ export function generateAuthenticationUrl(): string { - const oauth2Client = new google.auth.OAuth2( - '740987818053-dtflji3hfkn5r9t8ad6jb8740pls8moh.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' }); } /** |