aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-06-04 21:32:34 -0400
committerbobzel <zzzman@gmail.com>2025-06-04 21:32:34 -0400
commitf7cb0dcebb0514cf38f8a7e635ec9959c196145a (patch)
treee352a223a692d922e9f9780fd069d786f4c3bec1
parent8d424c8cb4d178d5fb92b6543d63fa409eb6430b (diff)
cleaned up getting client id/secret for google. fixed final message after going through authentication process.
-rw-r--r--src/server/ApiManagers/GeneralGoogleManager.ts39
-rw-r--r--src/server/apis/google/GoogleApiServerUtils.ts13
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' });
}
/**