Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It generates token with life duration = 1 hour #50

Closed
kay4444 opened this issue Dec 11, 2020 · 8 comments
Closed

It generates token with life duration = 1 hour #50

kay4444 opened this issue Dec 11, 2020 · 8 comments

Comments

@kay4444
Copy link

kay4444 commented Dec 11, 2020

I've created "Credentials.json" file as per instructions.
Then I am running the command to generate Token:
node ..\..\node_modules\gmail-tester\init.js .\credentials.json gmail_token.json [email protected]
It successfully creates Token, BUT it's life time is just 1 hour.

{
  "access_token": "ya29.a0AfH6SMDwy2 ... xMze5YfDMru-CYaM",
  "refresh_token": "1//09boFIYyEL0w3Cg ... UKq7eNZHeSKxIv3MyZqI",
  "scope": "https://www.googleapis.com/auth/gmail.readonly",
  "token_type": "Bearer",
  "expiry_date": 1610372897000
}

How extend token life time (to at least half of the year)?

@levz0r
Copy link
Owner

levz0r commented Dec 13, 2020

According to this, it looks like the access token is now expiring after one hour. I'll expose a function to refresh the access token in the coming days.

Thank you for bringing this to my attention.

@kay4444
Copy link
Author

kay4444 commented Dec 18, 2020

@levz0r
Are there any updates?

@levz0r
Copy link
Owner

levz0r commented Dec 18, 2020

Yes. I've just pushed a function refresh_access_token(credentials_json, token_path) to feature/refresh_token branch. Please check it out.
When you call the function, it will refresh the access token and save it back to token.json. Later this function might become part of get_messages function.
Let me know if it helps.

@kay4444
Copy link
Author

kay4444 commented Dec 18, 2020

@levz0r
Could you please clarify how can I call this function?
I use the following command to generate token:
node ....\node_modules\gmail-tester\init.js .\credentials.json gmail_token.json [email protected]
Should I update this command somehow to force your fix to work (generate token with correct duration time)?

@levz0r
Copy link
Owner

levz0r commented Dec 18, 2020

After creating token.json with init function you get an access token which is valid for one hour. You should basically check how old is your token (there is a field in token.json which has timestamp) and if it is older than one hour, you should call the refresh_access_token function which will extend it's validity by one more hour.

@C-E-Rios
Copy link

C-E-Rios commented Jan 4, 2021

Hey @levz0r , thanks for the branch. Will you be merging this any time soon?

@levz0r
Copy link
Owner

levz0r commented Jan 9, 2021

Can you guys please confirm the new method solves the issue?

@NikolaLohinski
Copy link

Hi @levz0r and thanks for the tool, it works perfectly fine with Cypress

The refresh_token seems to be working for me. I would love to see that in master

@levz0r levz0r closed this as completed in c816c46 Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants