Node.js google drive api - authorize without conse

2019-03-03 07:17发布

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.

2条回答
虎瘦雄心在
2楼-- · 2019-03-03 07:46

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

查看更多
我命由我不由天
3楼-- · 2019-03-03 07:54

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.

查看更多
登录 后发表回答