danthareja / node-google-apps-script

[DEPRECATED - use clasp instead] The easiest way to develop Google Apps Script projects
MIT License
353 stars 70 forks source link

add check for 'web' property on credentials object #51

Closed matthewbednarski closed 6 years ago

matthewbednarski commented 7 years ago

Add a check for web property in the credentials object, in case there is no installed property.

With my GApps account from my company the following command continued to fail:

$ gapps auth path/to/credentials.json

Here is the stack trace:

Error running auth command
Unhandled rejection Error: Path did not include "OAuth 2.0 client ID" credentials. Please check that you downloaded the right JSON credentials.
    at Object.ensureErrorObject (/usr/lib/node_modules/node-google-apps-script/node_modules/bluebird/js/main/util.js:261:20)
    at Promise._rejectCallback (/usr/lib/node_modules/node-google-apps-script/node_modules/bluebird/js/main/promise.js:472:22)
    at Promise._settlePromiseFromHandler (/usr/lib/node_modules/node-google-apps-script/node_modules/bluebird/js/main/promise.js:516:17)
    at Promise._settlePromiseAt (/usr/lib/node_modules/node-google-apps-script/node_modules/bluebird/js/main/promise.js:584:18)
    at Promise._settlePromises (/usr/lib/node_modules/node-google-apps-script/node_modules/bluebird/js/main/promise.js:700:14)
    at Async._drainQueue (/usr/lib/node_modules/node-google-apps-script/node_modules/bluebird/js/main/async.js:123:16)
    at Async._drainQueues (/usr/lib/node_modules/node-google-apps-script/node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues (/usr/lib/node_modules/node-google-apps-script/node_modules/bluebird/js/main/async.js:15:14)
    at runCallback (timers.js:651:20)
    at tryOnImmediate (timers.js:624:5)
    at processImmediate [as _immediateCallback] (timers.js:596:5)
laseryuan commented 7 years ago

Reference: https://developers.google.com/api-client-library/python/guide/aaa_client_secrets

rodyhaddad commented 7 years ago

I believe this happens when you choose Web Application instead of Other as the Application type of your credentials.
As described in this project's README, you should choose Other for your Credentials Application Type: create_client_id_-_test_gapps_deploy

So you can fix your error just by regenerating Credentials with an Application Type of Other, and running gapps auth again.

I don't think this project should support Credentials meant for Web Apps, since it's a CLI tool afterall.
I doubt the above "fix" is a hassle for users.
If anything, it pushes them to have separate Credentials for each platform that uses the API, eventually allowing them to revoke access to one but not the other.

I suggest you close this PR since the tool is working as expected imho.

laseryuan commented 7 years ago

Thanks. It is clear to me now. I was using the default credential, which is for running the script.

lricoy commented 6 years ago

Closing this as suggested by @rodyhaddad . @laseryuan if you are still interesting in merging this please reopen. I am not sure what are the implications of allowing web credentials but could take a look if needed.