gmail-tester icon indicating copy to clipboard operation
gmail-tester copied to clipboard

invalid_grant issue

Open dkoudrinhc opened this issue 4 years ago • 19 comments

Hi,

I've had the gmail-tester plugin work for a couple of days after setting it up, but then every few days it breaks with this error:

CypressError: cy.task('gmail:check') failed with the following error:

invalid_grant https://on.cypress.io/api/task

Anyone have any idea what could be going wrong here? I really need this to work consistently.

dkoudrinhc avatar Dec 01 '21 22:12 dkoudrinhc

Hello, Have you tried invoking refresh_access_token()?

levz0r avatar Dec 03 '21 08:12 levz0r

Hello, Have you tried invoking refresh_access_token()?

Not sure what that means sorry, is it mentioned anywhere in the documentation?

dkoudrinhc avatar Dec 03 '21 17:12 dkoudrinhc

Yes. Please try this: https://github.com/levz0r/gmail-tester#refresh_access_tokencredentials_json-token_path

levz0r avatar Dec 04 '21 14:12 levz0r

Yes. Please try this: https://github.com/levz0r/gmail-tester#refresh_access_tokencredentials_json-token_path

Still not sure how to use it. All it says in that readme is this: refresh_access_token(credentials_json, token_path) credentials_json: Path to credentials JSON file. token_path: Path to existing OAuth2 token file. Refresh the access token. A new file will overwrite the existing one in token_path.

From that I don't understand how to actually refresh a token, there's no code example, or anything.

dkoudrinhc avatar Dec 04 '21 19:12 dkoudrinhc

Yes. Please try this: https://github.com/levz0r/gmail-tester#refresh_access_tokencredentials_json-token_path

Still not sure how to use it. All it says in that readme is this: refresh_access_token(credentials_json, token_path) credentials_json: Path to credentials JSON file. token_path: Path to existing OAuth2 token file. Refresh the access token. A new file will overwrite the existing one in token_path.

From that I don't understand how to actually refresh a token, there's no code example, or anything.

following

MAfzalKhan1997 avatar Dec 05 '21 21:12 MAfzalKhan1997

same issue now also. I have built in the refresh token as a task:

on("task", { "gmail:refreshAccessToken": async args => { await gmail_tester.refresh_access_token( path.resolve("./cypress/support/gmail/", "client.json"), path.resolve("./cypress/support/gmail/", "token.json"), ); }, });

but it doesn't get a new token / generate a new file.

jbird21 avatar Dec 30 '21 14:12 jbird21

Same issue, I setup the credentials, and after about a week or so I get the message "invalid_grant", even though the expiration date is far away in the future.

Gamerdachs avatar Jan 18 '22 17:01 Gamerdachs

TO fix this i had to:

  • Delete existing Token
  • Run ./node setup (as per guide again) and then verify via Google. I wonder if it is something to do with Google more than the code itself ?

jbird21 avatar Jan 19 '22 08:01 jbird21

TO fix this i had to:

  • Delete existing Token
  • Run ./node setup (as per guide again) and then verify via Google. I wonder if it is something to do with Google more than the code itself ?

That doesn't really fix the problem, in 7 days you will get invalid_grant again. Still hoping someone is able to come up with a permanent solution.

dkoudrinhc avatar Feb 02 '22 00:02 dkoudrinhc

It would be a great solution to authenticate via Google Service Account @levz0r

Gamerdachs avatar Feb 02 '22 00:02 Gamerdachs

Hey, has anyone found a solution for that? Would the current implementation be able to use a Google Service Account?

tgecb avatar Oct 11 '22 11:10 tgecb

NOPE

jbird21 avatar Oct 11 '22 15:10 jbird21

+1

LukasLewandowski avatar Oct 12 '22 06:10 LukasLewandowski

It looks like its working fine, on cypress.config.js I have: on("task", { "gmail:refreshAccessToken": async args => { const token = await gmail_tester.refresh_access_token('./cypress/plugins/credentials.json', './cypress/plugins/token.json') return config } })

on test: cy.task("gmail:refreshAccessToken")

and expirydate (...."expiry_date":1665564390017}) is refreshed every time the task is launched.

TomaszCichon avatar Oct 12 '22 07:10 TomaszCichon

It looks like its working fine

It works fine for a week, then the token can't be refreshed anymore, returning this invalid_grant error

To elaborate on this, we can't refresh the token after a week because the OAuth consent screen managed in the Google cloud console is in testing mode. If we switch it to production mode, then the token could be refreshed indefinitely, but then the problem is that we can't use the authorization url generated by the init.js script in production mode anymore since october 3rd: https://developers.google.com/identity/protocols/oauth2/resources/oob-migration

tgecb avatar Oct 12 '22 09:10 tgecb

Any progress? Can we expect some solution to that problem? :)

LukasLewandowski avatar Oct 21 '22 06:10 LukasLewandowski

Any updates here? If the token can not be refreshed programatically, the use of the module is very limited.

dorisLi2014 avatar Dec 27 '22 22:12 dorisLi2014

It is big limitation in did, it forced me to switch to mail.tm

LukasLewandowski avatar Dec 28 '22 10:12 LukasLewandowski

@levz0r any help from your side to resolve this?

taninnazar avatar Jul 18 '23 11:07 taninnazar