cancel
Showing results for 
Search instead for 
Did you mean: 

My Google Home Requests time out when Google needs to refresh its Auth Token

ngriedel
Community Member

I'm developing an app, based from the smart home washer starter repo, that acts as a medium between google home and my device. 

 

So far every command and query has been working, but when the auth token I give google expires the first request after refresh times out. 

 

Normally:

1. "Hey Google, interact with my Device"

2. "Ok I have interacted with your device"

If the token needs to refresh:

1. "Hey Google, interact with my Device"

2. *Pauses for around 10 seconds* "I'm sorry I cannot reach your company service"

 

The weird thing is, logs show the refresh token function taking only 500ms, and the request still goes through to my device. The only real problem is that the google nest speaker doesn't SAY that the command was successful. 

 

The new token is still issued to google and works fine, the initial command works fine, but the smart home response is killer as it will give the appearance of failure every day (or however long a token is valid for). Is this a common issue with token refreshing?

 

LOGS for token function:


DEBUG 2023-07-11T23:02:49.683957198Z  Function execution took 400 ms, finished with status code: 200

 

Relevant Refresh Token code block

else if (grantType === "refresh_token") {
   

    const headers = {
      "Content-Type": "application/json",
    };

    let body = {
      refreshToken: request.body.refresh_token,
    };

    var requestOptions = {
      method: "POST",
      headers: headers,
      body: JSON.stringify(body),
    };
    await fetch(${companyloginURL}, requestOptions)
      .then((res) => res.json())
      .then((res) => {
        if (res.status == 200) {
          obj = {
            token_type: "Bearer",
            access_token: res.data.access_token,
            expires_in: expiresIn, //1 day
          };
        }
      })
      .catch((err) => {
        functions.logger.info("refreshtoken Error", err);

        response.status(500);
      });
  }
  response.status(HTTP_STATUS_OK).json(obj);

 

 

 

 

1 Recommended Answer

sipriyadarshi
Solutions Expert
Solutions Expert
  • This is not the behavior for a working token refresh. When you give or provide a new Auth token to Google it should start working again. 
  • Can you please verify the following :
    • A) Check if you are providing a new access token and not making use of the old token.
    • B) Can you check for Status Code 200 when your access token expires and when you generate a new token ?
  • When we do the request to you guys do you get the Access Token (new one or the old one ). Can you validate it a few times ?

View Recommended Answer in original post

7 REPLIES 7

sipriyadarshi
Solutions Expert
Solutions Expert
  • This is not the behavior for a working token refresh. When you give or provide a new Auth token to Google it should start working again. 
  • Can you please verify the following :
    • A) Check if you are providing a new access token and not making use of the old token.
    • B) Can you check for Status Code 200 when your access token expires and when you generate a new token ?
  • When we do the request to you guys do you get the Access Token (new one or the old one ). Can you validate it a few times ?

#

Hello Sipriyadarshi. I just wanted to ping you in case you didn't see my reply. I realized that I didn't reply directly to your answer.

ngriedel
Community Member

Hello sipriyadarshi,

 

I have verified the following:

A) When the old access_token expires the new one issued in the "refresh token" function is the same that google gives in the subsequent repsonses. 

To elaborate:

  • Call 10 seconds before token expires: Auth Token 1 is returned by google to my app.
  • Call 10 seconds after token expires : Refresh route hit, Auth Token 2 given back to google, and Auth Token 2 returned by Google  when making 2nd call 


     


    B) All function calls both to my service and my company backend API's are returning 200 status OK. 

    As far as all of my checks go, all under the hood functionality is working properly. The refresh route is hit when the token expires, the new auth token is given to google, google then uses this new token to make the new call, and all device functionality is responsive as expected. 

    Only the nest speaker is timing out and saying that the service is unavailable when the refresh token function is being called. 

    Also IMPORANT DISTINCITON:
    This behavior happens ONLY when using voice control through the nest mini speaker. If you send the exact same command through the google home app on your phone using the touch UI, there is no lag and everything behaves as expected. It should be noted that using google assistant on the phone also works, but there does seem to be a slight delay like with the nest. This is why I suspect the nest has some timeout that is out of my control.


Additional data that may help:

When the token expiry is 10 mins, the timeout happens every time there is a refresh. However, if I change the token expiry to 5 minutes, there will be no timeout if I make a request every 5 minutes, after the token expires. 

BUT if I wait 10 minutes to make a new call, the timeout still happens.

Povdylen
Community Member

#

 

 

nilushan
Community Member

I have the same issue.

When issuing a voice command after about 1 hour, ( possibly the access token has expired, and needs a new token)  there is a long delay of about 5 - 10 seconds. Google Home speakers respond with "I cannot reach <name> " . Most of the time the exec command gets executed and the action happens. 

I also noticed that token refresh and EXEC api calls are less than 1 second. 

 

Have no idea what is the issue.