google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

Issue with gmail authentication

Open spotlmnop opened this issue 12 years ago • 5 comments

We are trying to create a node server to read email. We are getting a 500 error after JWT authentication when we are trying to read list of emails.

Here is the gist

https://gist.github.com/spotlmnop/a35ccfbd5c55d549c32e

spotlmnop avatar Aug 02 '14 15:08 spotlmnop

In order to read a user's email, you need to do OAuth2 authentication with that user and get them to accept the permissions you request. Here you're authenticating with a JWT which is effectively an API-only google account ([email protected]) lacking many user-facing features such as GMail. Does this make sense?

ryanseys avatar Aug 02 '14 16:08 ryanseys

If you operate within a Google Apps domain you can use Domain-wide delegation of authority and then impersonate the user whose data you need to access.

For personal accounts, you will have to use standard Oauth 2.0 flow.

robertrossmann avatar Aug 02 '14 17:08 robertrossmann

@Alaneor Thanks a ton. Yep, we ended up going oauth 2.0 flow. @ryanseys I did not get it until you explained me. Thank you for your elaborate explanation.

spotlmnop avatar Aug 08 '14 22:08 spotlmnop

@spotlmnop can you post a gist sample of gmail oauth2 flow, please

navaru avatar Aug 09 '14 13:08 navaru

@navaru You can see an example of OAuth2 flow here: https://github.com/google/google-api-nodejs-client/blob/master/examples/oauth2.js

ryanseys avatar Aug 09 '14 17:08 ryanseys