Getting `nil` for id token
Hi, this is sort-of-a cross-post with the Defold forums here: https://forum.defold.com/t/need-help-getting-id-token-from-google-play-services/73719
I'm trying to get an id_token from GPGS but I keep getting nil. I've set up the game.project with a client_id and request_id_token=1, but am not sure if I should be adding the Android Credentials client_id or a Web Credential client_id from the GCP panel.
The sign in is successful and I get the id and display name for my sign in, but I need the id_token as well for further authentication against Supabase in my case.
Can you help me with nailing down the cause of this? What might I be doing wrong?
Some quick code from my attempts (I try a silent login, and if that fails, I show a "sign in with Google" button.
function init(self)
local welcome_gui_url = msg.url("main:/welcome#welcome")
local function gpgs_callback(self, message_id, message)
if message_id == gpgs.MSG_SIGN_IN or message_id == gpgs.MSG_SILENT_SIGN_IN then
if message.status == gpgs.STATUS_SUCCESS then
print("Signed in")
print(gpgs.get_id())
print(gpgs.get_display_name())
print(gpgs.get_id_token())
msg.post(welcome_gui_url, "set_sign_in_visibility", { visible = false })
else
print("Sign in error!")
print(message.error)
msg.post(welcome_gui_url, "set_sign_in_visibility", { visible = true })
end
elseif message_id == gpgs.MSG_SIGN_OUT then
print("Signed out")
msg.post(welcome_gui_url, "set_sign_in_visibility", { visible = true })
end
end
if gpgs then
gpgs.set_callback(gpgs_callback)
gpgs.silent_login()
else
print("No gpgs")
msg.post(welcome_gui_url, "set_sign_in_visibility", { visible = false })
end
end
Hmm, I put the call to get the id token elsewhere in the code, e.g. when I click somewhere on the screen, and the token was valid there (and not nil). I wrote some more details in the forum post I mentioned.
This probably has something to do with network latency or some other "race condition" issue :shrug:
Still getting this issue inside the callback function
Still getting this issue inside the callback function
So you are calling gpgs.get_id_token() from within the callback when message.status == gpgs.STATUS_SUCCESS ?
Could you please try something like this with a timer.delay() to see if it is a timing issue:
function init(self)
local function gpgs_callback(self, message_id, message)
if message_id == gpgs.MSG_SIGN_IN or message_id == gpgs.MSG_SILENT_SIGN_IN then
if message.status == gpgs.STATUS_SUCCESS then
print("token", gpgs.get_id_token())
timer.delay(2, false, function()
print("token after delay", gpgs.get_id_token())
end)
end
end
if gpgs then
gpgs.set_callback(gpgs_callback)
gpgs.silent_login()
end
end
So, I didn't turn on request_id_token in game.project file. When I set request_id_token = 1, the GPGS popop doesn't show and in the callback I'm getting response in message as error = "Sign-in failed: DEVELOPER_ERROR (10). I've setup client_id, SHA-1 in .keystore file and added the client_id in google play console. IDK what I'm doing wrong.
DEVELOPER_ERROR
This seems relevant to your problem: https://stackoverflow.com/q/77466444