aboutsummaryrefslogtreecommitdiff
path: root/src/server/apis/google/GoogleApiServerUtils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/apis/google/GoogleApiServerUtils.ts')
-rw-r--r--src/server/apis/google/GoogleApiServerUtils.ts7
1 files changed, 3 insertions, 4 deletions
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);