4

I'm interesting is this possible to use Google Drive API without consent screen in Node.js app?

  • I want using only account where I enable app engine. Api must have full permission to save file, share file, delete file.
  • My app will be deploy to heroku.

I'm get example from quickstart from Google Drive API, but I don't have idea how I can do this.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449

2 Answers2

1

What you are looking for is called a service account. Service accounts are dummy users that have their own drive account. They can also be granted permission to your personal drive account by sharing a folder or file with them like you would any other user. Because service accounts are preauthorized there is no consent screen.

I am not a Node.js developer but i found this. Accessing Google API using Service Account in Node.js

var CLIENT_ID = env.googleapis.client_id;
var CLIENT_SECRET = env.googleapis.client_secret;
var oauth2 = new googleapis.OAuth2Client(CLIENT_ID, CLIENT_SECRET, 'postmessage');

var SERVICE_ACCOUNT_EMAIL = 'email@serviceaccount.com';
var SERVICE_ACCOUNT_KEY_FILE = '/path/to/decrypted/key/file';
var jwt = new googleapis.auth.JWT(
        SERVICE_ACCOUNT_EMAIL,
        SERVICE_ACCOUNT_KEY_FILE,
        null,
        ['https://www.googleapis.com/auth/analytics.readonly']);

I also have a tutorial on service accounts if you are interested in understanding how they work and how to set one up. Google developer console service account

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • Thanks for answer! This works, but when I send file I don't see it on my account. Is there other place where service account stored files? – Michał Niedziela Apr 20 '17 at 11:18
  • Thats because a service account is not you its going to be stored on the service accounts account make a directory on your own account share the directory with the Service account like you would any other user then upload to that directory instead. Or have the service account grant you access to its directory by sharing it with you. – Linda Lawton - DaImTo Apr 20 '17 at 11:45
  • Do permissions create on the folderid. for the service account. Remember folders and files are the same thing. https://developers.google.com/drive/v3/reference/permissions/create – Linda Lawton - DaImTo Apr 20 '17 at 11:47
1

Do not use a Service Account. It doesn't do what you think it does. What you need is a stored Refresh Token for your Google Account. I've set out all of the steps at How do I authorise an app (web or installed) without user intervention? (canonical ?) , including sample JavaScript which will run under node.

Community
  • 1
  • 1
pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • Tkanks for answer. Service account realy isn't what I want. So I want store my refresh_token into environments variable and use your code to getting token. – Michał Niedziela Apr 21 '17 at 05:18