Socket
Socket
Sign inDemoInstall

utils-google-drive

Package Overview
Dependencies
53
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.2 to 3.0.3

7

CHANGELOG.md

@@ -0,6 +1,9 @@

### v3.0.3 — *April 9, 2021*
* Fixed `batch` and `refreshAccessToken` referencing token before creation
### v3.0.2 — *February 24, 2021*
* Fixed del returning before overwrite complete
* Fixed `del` returning before overwrite complete
### v3.0.1 — *November 18, 2020*
* Fixed examples for makeFolder and upload methods
* Fixed examples for `makeFolder` and `upload` methods

@@ -7,0 +10,0 @@ ### v3.0.0 — *November 11, 2020*

@@ -54,3 +54,3 @@ #!/usr/bin/env node

this.del = del.del;
this.batch = batch.batch;
this.batch = drive._addDrive(batch, this);
this.throttle = throttle;

@@ -57,0 +57,0 @@

#!/usr/bin/env node
'use strict';
const fs = require('fs');
const gaxios = require('gaxios');
const _refreshAccessToken = require('./refreshAccessToken');
// get token from file
const tokenData = JSON.parse(fs.readFileSync('tokenGDrive.json', 'utf8'));
let token = [tokenData.token_type, tokenData.access_token].join(' ');
module.exports = batch;
module.exports = {batch};
/**

@@ -43,2 +38,9 @@ * Makes a batch request.

// refresh access token if needed
// eslint-disable-next-line
const tokenType = this.drive.permissions.context._options.auth.credentials.token_type;
let token = [
tokenType,
this.drive.permissions.context._options.auth.credentials.access_token,
].join(' ');
const firstRequestOpts = requests[0];

@@ -53,4 +55,4 @@ firstRequestOpts.headers = {

if (e.response.status === 401) {
const newAccessToken = await _refreshAccessToken();
token = [tokenData.token_type, newAccessToken].join(' ');
const newAccessToken = await _refreshAccessToken(this);
token = [tokenType, newAccessToken].join(' ');
}

@@ -57,0 +59,0 @@ }

@@ -34,1 +34,2 @@ 'use strict';

}

@@ -8,14 +8,5 @@ #!/usr/bin/env node

const refreshEndpoint = 'https://accounts.google.com/o/oauth2/token';
const tokenGDrive = JSON.parse(fs.readFileSync('tokenGDrive.json'));
const credentialsGDrive = JSON.parse(
fs.readFileSync('credentialsGDrive.json')).installed;
const refreshAccessTokenOpts = {
const refreshTokenOpts = {
url: refreshEndpoint,
method: 'POST',
body: JSON.stringify({
'client_id': credentialsGDrive.client_id,
'client_secret': credentialsGDrive.client_secret,
'refresh_token': tokenGDrive.refresh_token,
'grant_type': 'refresh_token',
}),
};

@@ -27,7 +18,17 @@

* Refreshes access token and updates tokenGDrive.json accordingly.
* @return {String} New access token
* @param {UtilsGDive} utilsGDrive - instance of UtilsGDrive
* @return {string} New access token
* @access private
*/
async function _refreshAccessToken() {
const res = await gaxios.request(refreshAccessTokenOpts);
async function _refreshAccessToken(utilsGDrive) {
refreshTokenOpts.body = JSON.stringify({
/* eslint-disable */
client_id: utilsGDrive.drive.permissions.context._options.auth._clientId,
client_secret: utilsGDrive.drive.permissions.context._options.auth._clientSecret,
refresh_token: utilsGDrive.drive.permissions.context._options.auth.credentials.refresh_token,
grant_type: 'refresh_token',
/* eslint-enable */
});
const res = await gaxios.request(refreshTokenOpts);
const tokenGDrive = JSON.parse(fs.readFileSync('tokenGDrive.json'));
tokenGDrive.access_token = res.data.access_token;

@@ -34,0 +35,0 @@ const expiryDate = new Date().getTime() + res.data.expires_in - 60;

{
"name": "utils-google-drive",
"version": "3.0.2",
"version": "3.0.3",
"description": "A simple and flexible package for interacting with Google Drive",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc