3

I'm having some issues with the realtime API reconnecting properly after a laptop/phone comes back from sleep/standby. The API properly detects that it needs to have a refresh OAuth token and throws an error, however once the token has been refreshed the realtime API does not correctly reconnect to the remote service. This is somewhat similar to (Part 2), however this only occurs after a couple hours of a lost connection.

I would expect that after the OAuth token is refresh, the realtime API would pick it up and resync itself with the remote server. Instead, it appears that the realtime API thinks it is in a valid state and makes modifications locally, but does not resync with the remote server.

// Valid Auth Token
Object {state: "", access_token: "ya29.AHES6ZS38RR9kVX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", token_type: "Bearer", expires_in: "3600", client_id: "XXXXXXXXXXXXXXX.apps.googleusercontent.com"…}
_aa: "1"
access_token: "ya29.AHES6ZS38RR9kVX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
client_id: "XXXXXXXXXXXXXXX.apps.googleusercontent.com"
cookie_policy: undefined
expires_at: "1381916402"
expires_in: "3600"
g_user_cookie_policy: undefined
issued_at: "1381912802"
response_type: "token"
scope: Array[3]
state: ""
token_type: "Bearer"

// Current Time
Date.now()
1381912845180 [Wed Oct 16 2013 01:40:45 GMT-0700 (Pacific Daylight Time)]

// <<Computer Sleep For Hours>>
Uncaught Error: Authentication error: No token set api:462

Drive Realtime API Error: token_refresh_required: The OAuth token must be refreshed. api:464
Doc Load Error:  Rw {type: "token_refresh_required", message: "The OAuth token must be refreshed.", b: false, isFatal: false} 

// <<Refresh OAuth Token>>

// Current Time
Date.now()
1381959164975 [Wed Oct 16 2013 14:32:44 GMT-0700 (Pacific Daylight Time)]

// Valid Auth Token
Object {state: "", access_token: "ya29.AHES6ZRkwocCBwxj_h7Zx2_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", token_type: "Bearer", expires_in: "3600", client_id: "XXXXXXXXXXXXXXX.apps.googleusercontent.com"…}
_aa: "1"
access_token: "ya29.AHES6ZRkwocCBwxj_h7Zx2_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
client_id: "XXXXXXXXXXXXXXX.apps.googleusercontent.com"
cookie_policy: undefined
expires_at: "1381962143"
expires_in: "3600"
g_user_cookie_policy: undefined
issued_at: "1381958543"
response_type: "token"
scope: Array[3]
state: ""
token_type: "Bearer"

// Current Value
LOCAL.data.get("t")
"0.502 Beta 3:"

// Editing Value
LOCAL.data.set("t", "0.502 Beta 4:")
Mm {a: ""0.502 Beta 3:"", Ma: Object, K: function, oa: function, J: function…}

// Edit "Worked"
LOCAL.data.get("t")
"0.502 Beta 4:"

// <<Refresh Page>>

// Current Value
LOCAL.data.get("t")
"0.502 Beta 3:"

Making edits to the realtime model works after the OAuth refresh, but the edits do not persist. Is this a valid scenario that the API supports? Is there any additional information I can give that would make identifying the problem easier?

Community
  • 1
  • 1
Grant Watters
  • 660
  • 4
  • 16
  • How are you refreshing the token? Are you calling gapi.auth.authorize(), or are you using some other API? In general, the Realtime API should reconnect, even if it has been idle for hours or the computer has been asleep. It would also help if you could examine the HTTP request panel and post any errors. – Brian Cairns Apr 09 '14 at 20:00
  • I believe that we finally have a fix for this issue. We are planning on pushing the fix next week. Thanks for all of the help debugging this! It was tricky to track down! – Brian Cairns Jun 24 '14 at 21:26
  • Having the same issue here: After some hours of inactivity, the token_refresh_required error is fired and we found no way to revalidate it. @BrianCairns: Would be great, if you could share the fix! – aemkei Jul 04 '14 at 07:18
  • 1
    Hi aemkei - When the token_refresh_required is fired you should handle the error by calling gapi.auth.authorize again with immediate:true. (If you're using gapi.auth.signIn for authorization you probably want to use that instead.) For our app we generally preemptively refresh the auth token before it has a chance to expire, you can do this using the expires_in field returned on the token. – Grant Watters Jul 05 '14 at 20:42

0 Answers0