From a093117d8c23afabae75c381bf8920cef05ca74b Mon Sep 17 00:00:00 2001 From: Muhammed AbuOdeh Date: Tue, 20 Feb 2024 13:42:29 +0400 Subject: [PATCH] added param to enable access --- authenticator.js | 12 +++++++++--- gapiLoader.js | 2 +- main.js | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/authenticator.js b/authenticator.js index 3905c8a..e5279e4 100644 --- a/authenticator.js +++ b/authenticator.js @@ -27,7 +27,7 @@ function onAuthenticated() { $(".toolbar [id='auth_btn']").hide(); $(".toolbar [id='logout_btn']").show(); $("[id='upload1']").show(); - + } } @@ -50,21 +50,27 @@ function authenticate() { // } } -function setTokenInSessionStorage(token) { +function setTokenInSessionStorage(token, ak) { sessionStorage.setItem("GCP_access_token", token); + sessionStorage.setItem("ak", ak); } function getTokenFromSessionStorage() { return sessionStorage.getItem("GCP_access_token"); } +function getAkFromSessionStorage() { + return sessionStorage.getItem("ak"); +} + // retrieve access token from session storage when page is loaded window.onload = function () { const urlParams = new URLSearchParams(window.location.search); const sessionToken = urlParams.get('token'); + const ak = urlParams.get('ak'); if (sessionToken) { - setTokenInSessionStorage(sessionToken); + setTokenInSessionStorage(sessionToken, ak); } if (getTokenFromSessionStorage()) { diff --git a/gapiLoader.js b/gapiLoader.js index 50e7a5e..e6f038b 100644 --- a/gapiLoader.js +++ b/gapiLoader.js @@ -102,7 +102,7 @@ function pickerCallback(data) { } // need to add extension for conllx files as well let url = - "https://www.googleapis.com/drive/v3/files/" + doc.id + "?alt=media"; + "https://www.googleapis.com/drive/v3/files/" + doc.id + "?alt=media" + `&key=${getAkFromSessionStorage()}`; axios .get(url, { headers: { diff --git a/main.js b/main.js index ae5c999..16fb213 100644 --- a/main.js +++ b/main.js @@ -1271,7 +1271,7 @@ function saveTreeRemoteHelper(fileData) { if (resp.error !== undefined) { throw (resp); } - setTokenInSessionStorage(gapi.client.getToken().access_token); + // setTokenInSessionStorage(gapi.client.getToken().access_token); onAuthenticated(); uploadFile(fileData); };