I finally figured it out. In my case, the Gmail scope("https://mail.google.com/") was missing, from the token generation process. It works fine now.
EDIT:
(Including comment from @ohmyfromage:)
When you call generateAuthUrl
, you need to pass an object with an array scope of strings as the scopes, and one of those strings is "https://mail.google.com/"