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

Token expire after 7 days #56

Open
muhammadmubeen12345 opened this issue Apr 3, 2021 · 23 comments
Open

Token expire after 7 days #56

muhammadmubeen12345 opened this issue Apr 3, 2021 · 23 comments

Comments

@muhammadmubeen12345
Copy link

How to automatically update the token in gmail API.

@damasofc
Copy link

damasofc commented Apr 5, 2021

I'm with the same issue, of course I know about the function refresh-token that @levz0r created, but even using that function returns me an error "invalid_grant", if you could give us a complete example on how to use refresh-token would be great @levz0r

thank you in advanced

@pakhilov
Copy link

I have the same problem and API for the refresh token doesn't work

@LordA98
Copy link

LordA98 commented Jun 9, 2021

Yeah I have the same problem. Not sure how long it's lasting exactly but the refresh_access_token function is not working.

@LordA98
Copy link

LordA98 commented Jun 12, 2021

@muhammadmubeen12345 @damasofc @pakhilov

Did any of you find a solution / workaround in the end?

@muhammadmubeen12345
Copy link
Author

muhammadmubeen12345 commented Jun 12, 2021

@LordA98 I have not found any solution about update of token automatically. Every Monday I update the token manually...

@riccardogiorato
Copy link

riccardogiorato commented Aug 29, 2021

Hey @LordA98 and @muhammadmubeen12345 have you both tried "refresh_access_token"?

I just added to my cypress project easily with this file: refreshGmailToken.ts.

image

I then call this script on each CI run uploading the new token to S3 here: github workflow!

image

This will be downloaded by the following runs!

I hope I was able to help you and if you need more help just let me know!
If I helped you can star my repository here where I test all sort of stuff with cypress, gmail and more: https://github.com/riccardogiorato/cypress-for-everything

@the-bmc-dev
Copy link

Hey @LordA98 and @muhammadmubeen12345 have you both tried "refresh_access_token"?

I just added to my cypress project easily with this file: refreshGmailToken.ts.

image

I then call this script on each CI run uploading the new token to S3 here: github workflow!

image

This will be downloaded by the following runs!

I hope I was able to help you and if you need more help just let me know! If I helped you can star my repository here where I test all sort of stuff with cypress, gmail and more: https://github.com/riccardogiorato/cypress-for-everything

Yes, even after using the refresh_access_token function, the 'invalid_grant' error will eventually show up.

@levz0r
Copy link
Owner

levz0r commented Nov 22, 2021

@the-bmc-dev can it be because you are scanning the inbox too frequently of using broad filters?

@the-bmc-dev
Copy link

the-bmc-dev commented Nov 23, 2021

@levz0r I did not think about that, are there such restrictions on Gmail API?
Edit: I've checked the quotas and none of them were reached.

@omersomuncu
Copy link

omersomuncu commented Dec 21, 2021

Hi,
I created this in plugins/index.js
on("task", { "gmail:refresh_access_token": async () => { const token = await gmail_tester.refresh_access_token( path.resolve(__dirname, "credentials.json"), path.resolve(__dirname, "token.json") ); console.log("Refreshed the gmail token!"); return token; }, });

Screenshot 2021-12-21 at 12 00 51

and I call it like this in my test:
cy.task("gmail:refresh_access_token");

I am getting this error:

`cy.task('gmail:refresh_access_token') failed with the following error:

> No refresh token is set.`

Any idea where do I make mistake?

@dkoudrinhc
Copy link

Hi, I created this in plugins/index.js on("task", { "gmail:refresh_access_token": async () => { const token = await gmail_tester.refresh_access_token( path.resolve(__dirname, "credentials.json"), path.resolve(__dirname, "token.json") ); console.log("Refreshed the gmail token!"); return token; }, });

Screenshot 2021-12-21 at 12 00 51

and I call it like this in my test: cy.task("gmail:refresh_access_token");

I am getting this error:

`cy.task('gmail:refresh_access_token') failed with the following error:

> No refresh token is set.`

Any idea where do I make mistake?

Thanks for the code example. I too would love to hear how others are using it, otherwise without a fully working refresh token they expire every two days so the whole plugin becomes not very useful.

@omersomuncu
Copy link

Hey folks,

I find the solution.

First of all, do not forget to add "refresh_token":"Your token" to your token.json!!!
After that index.js:
Screenshot 2021-12-28 at 13 04 04

It's ready to test: cy.task("gmail:refresh_access_token", {});

Have fun!

@dkoudrinhc
Copy link

Hey folks,

I find the solution.

First of all, do not forget to add "refresh_token":"Your token" to your token.json!!! After that index.js: Screenshot 2021-12-28 at 13 04 04

It's ready to test: cy.task("gmail:refresh_access_token", {});

Have fun!

Unfortunately this didn't seem to help at all, it just says 'invalid_grant' when running the refresh_token task now. e.g. CypressError: cy.task('gmail:refresh_access_token') failed with the following error:

invalid_grant

@josego1984
Copy link

Hi,
I'm using the refress_access_token function but it requires to open a url and the copy again the code. Is there any way to avoid this?

@digitalgopnik
Copy link

Hey folks,

I find the solution.

First of all, do not forget to add "refresh_token":"Your token" to your token.json!!! After that index.js: Screenshot 2021-12-28 at 13 04 04

It's ready to test: cy.task("gmail:refresh_access_token", {});

Have fun!

@omersomuncu Check this issue. The key refresh_token should be set, check your applicationtype-setting for the client -> should be Desktop app

@taninnazar
Copy link

@levz0r could you please help to resolve this issue?

@Revadike
Copy link

would be nice to have this done automatically
also, the above solutions only work if you save token.json file to disk

@mariamaslam
Copy link

Hi @omersomuncu im trying to solution i don't have a CI/CD pipeline. I am just executing the test from terminal. How can i automatically refresh the token?
Please can anyone support ?
@Revadike @taninnazar @levz0r

@taninnazar
Copy link

@mariamaslam there is nothing to do with a code. To have a stable token you need to change the Publishing status of your Google app from "In testing" to "In production". You can do it here - https://console.cloud.google.com/apis/credentials/consent

@mariamaslam
Copy link

Hi @taninnazar thank you quick response, so once changed to "in production" the token will not expire right?

@taninnazar
Copy link

Hi @mariamaslam , the token will expire but more rarely - like once a year or once a half year

@mariamaslam
Copy link

Amazinggg @taninnazar do i just need to change the permission n that would be it or do i need to re- generate the token with gmail-tester?

@harishdhande01
Copy link

aany solution @mariamaslam

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