1

can someone guide me in creating a auth object for following code!

const upload = require('google-drive-uploader');
 
const {id, size, md5, mimeType} = await upload({
  path: '/path/to/file.mov',
  folderId: '...Google Drive folder ID...',
  auth: /* Google Drive auth object */
});
noob
  • 11
  • 1

1 Answers1

0

You have two options to obtain auth

  1. The google-drive-uploader package provides its own authentication method: simply define
const auth = await upload.authenticate({
  email: 'EMAIL',
  privateKey: 'PRIVATE KEY'
});
  1. The conventional Google libray method is
const {JWT} = require('google-auth-library');
 
const auth = new JWT(
  'EMAIL',
  null,
  'PRIVATE KEY',
  ['https://www.googleapis.com/auth/drive']
);
 
await auth.authorize();

For both options, a privateKey is a credential that you obtain when creating a service account

In other words, to use this ppackage, you need to create a Google Service account, as described here

  • When working with a service account, EMAIL is the email of the service account - not your own email
  • When using a service account - you should give to the service account access to your drive - if you want it to upload files to your drive
  • Alternatively you can use impersonation in combination with domain-wide delegation
  • The latter allows the service account to act as "you", so you do not need to exlicitly share with it your Drive and files
  • See here for a sample on how to create a JWT authentication client with impersonation
ziganotschka
  • 25,866
  • 2
  • 16
  • 33