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

Can't download even though Authentication successful #8

Closed victorhaggqvist closed 9 years ago

victorhaggqvist commented 9 years ago
$ gaps init ~/Downloads/client_secret_361575934155-vc7kl330k14upfnddddddddddf8kl0fjm.apps.googleusercontent.com.json

Please visit the following url in your browser (you'll only have to do this once): https://accounts.google.com/o/oauth2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.scripts&response_type=code&client_id=361575934155-vxxxxxxxxxxxxxxxxxxxxxupfnp8ogir69mf8kl0fjm.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fwww.example.com%2Foauth2callback

Look in the url for ?code=XXXXXXXXX and copy everything after the '='
Enter the code here: 4/xxxxxxxxxxxxxxxxxxxxxxxxxxxnKH-jRlhP5guNABYf7LJScV6Y.0kYFEdqDmYEXrjMoGjtSfTo-mI7RmgI#
Authentication successful! Ready to sync.

$ gaps download MZjBBzk9OmQAiUEj17zVxxxxxxxxxxxxxxxxxxxx                                                                  
Error in authenticate module [Error: No refresh token is set.]

I'm on Arch Linux with $ node --version && npm --version v0.12.3 2.10.0

Let me know if I can provide any more info to help out.

danthareja commented 9 years ago

How interesting. gaps stores a local config in ~/.gaps. Can you check this file to see if there is a refresh_token property there? If not, can you try delete the file and run gaps init again?

victorhaggqvist commented 9 years ago

My bad, missed the notification of your reply.

There seem to be no refresh_token.

Tried once again today, no luck.

$ cat ~/.gaps 
{
  "client_id": "360000004155-vc7kl330k14upfnp8ogir69mf8kl0fjm.apps.googleusercontent.com",
  "client_secret": "UcP5-Lj6SwfwffwefwewfeMqAWHsWg",
  "redirect_uri": "https://www.example.com/oauth2callback"
}
szaboadorian commented 9 years ago

Hello,

I have the same issue, but on my side I managed to track it down: as stated here https://developers.google.com/identity/protocols/OAuth2WebServer - when access_type="offline", "This will result in your application obtaining a refresh token the first time your application exchanges an authorization code for a user.".

As the refresh token is passed only first time, I assume this is the second time you have run the the init on the same URL, so refresh token was not passed anymore

To fix this, I would suggest adding in the init.js, the "approval_prompt": 'force' parameter as well (http://stackoverflow.com/questions/8942340/get-refresh-token-google-api). As per above link: " If the value is force, then the user sees a consent page even if they previously gave consent to your application for a given set of scopes."

var url = oauth2Client.generateAuthUrl({ access_type: 'offline', // Required to receive a refresh token scope: GOOGLE_AUTH_SCOPE, approval_prompt: 'force' });

Thanks, Ado

danthareja commented 9 years ago

Great find @szaboadorian, I had totally forgotten about the approval_prompt property. I'll fix this in the next patch

danthareja commented 9 years ago

@victorhaggqvist can you confirm this works?