Google calendar - Authentication code expired

Hi, After upgrading to 2022.5 I am having problems with my google calendar. everything was working fine and I have a lot of automations based on calendar events. After upgrading to 2022.5 it just did not load anymore. I have tried to remove it and install it again but now I get the “Authentication code expired or credential setup is invalid, please try again.” message when adding it.
Any ideas on what can I do to fix it?
I’m running a supervised home assistant on a virtual box

Likely before it was failing silently, and now it fails explicitly.

I would recommend double checking the setup in Google Calendars - Home Assistant for the credential that you are using.

Thanks for the reply,
I have re-installed it creating the client Id and secret. I still get the same error

OK perhaps then try enabling debugging as described here Error trying to reauthenticate google calendar · Issue #71115 · home-assistant/core · GitHub and you may get a more explicit error message from the server about the problem.

So this is what i get :

  • DEBUG (MainThread) [homeassistant.components.google.config_flow] Creating DeviceAuth flow

Then i enter the code to google and approve it.

  • DEBUG (MainThread) [homeassistant.components.google.api] Attempting OAuth code exchange

This message appears 12 times
then i get “Authentication code expired or credential setup is invalid, please try again” and after that :

  • DEBUG (MainThread) [homeassistant.components.google.api] Token not yet ready; trying again later

OK all that looks normal as “token not yet ready; trying again later” happens while it is waiting for you to enter the code in Google. Nothing else in the logs after that?

Can you confirm a few things:

  • the account you are using in the cloud console is the same you are logging in with
  • the type of credential created in google cloud console
  • confirm api is enabeld?
  • date/times on home assistant computer are all reasonable (e.g. not set to 10 years ago)

I don’t have many other ideas other than continuing to check everything against the instructions again.

I’m using the same account on both.
credentials are “OAuth 2.0” for " TV and Limited Input"
Google Calendar API is enabled
date/time is : Sat May 14 14:30:32 PDT 2022

I did however notice that my HA is a bit slow when starting.

I will try and disable all devices and try again

I have been trying to fix this for almost two weeks now …
Thank you for your help.
I’ll post a solution if I find it

Does it work if the oauth consent screen is set to production?

No, The same thing when in production

Perhaps one idea could be to revert to the old version you were using and see if the setup works again. If it does, that would be pretty surprising, but would be useful information. Then, if you upgrade again to 2022.5 and it fails it would be helpful to capture the error detail before re-installing.

Try deleting .google_token from your config folder and restart HA. I believe this should force it to authenticate again. Then you would see a notification asking for a code and set up using the link in there.

I don’t have .google_token file in config folder

It’s a hidden file I believe. So depending on what you use to view the drive, make sure you have access to hidden files. I use the File editor add-on on HA (through the add-on store). I can see the file at the very top of my file list.

In the past when I had an issue, deleting that file and restarting HA forced it to start the setup again.

That file is no longer used.

Hi,
I have found the problem with the google calendar.
It seems that my Virtual box was running very slow and this was causing problems with google calendar and a few other things.
I have moved my homeassistant to Debian 11 tablet (supervised version) and now it works.
Thanks for your help

I have the same problem - Getting the same “Authentication code expired or credential setup is invalid, please try again.” message when trying to setup calendars.

I am also running HA in a VM (on unRAID).

How do I solve this without moving my setup to a different server/host?

I have realized that in my case it was running too slow. now I have installed a Debian OS with a supervised Home assistant. and it works much better than it was on VM

Anything in the error logs? The main issue is likely that the credentials are not setup correctly, so double check the instructions.