Need help getting id token from Google Play Services (SOLVED)

After it took me a while to realize that if my gpgs.silent_login() fails, I should call gpgs.login() or something like that (should I?), I got myself signed in but calling gpgs.get_id_token() returns nil. I need the id token to authenticate with my Supabase-based backend for some stuff. I set up game.project properly, I believe.

game.project:

[gpgs]
app_id = <I put my app number here>
use_saved_games = 0
request_server_auth_code = 0
request_id_token = 1
client_id = somethingsomethingsomething.apps.googleusercontent.com

login code (for now in main.script):

function init(self)
	local tried_login = false
	print("HELLO!!!!")
	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()) -- print nil :(
			else
				print("Sign in error!")
				print(message.error)
				if not tried_login then
					tried_login = true
					gpgs.login()
				end
			end
		elseif message_id == gpgs.MSG_SIGN_OUT then
			print("Signed out")
		end
	end


	if gpgs then
		gpgs.set_callback(gpgs_callback)
		gpgs.silent_login()
	else
		print("No gpgs")
	end
end

Additionally, I’m not sure if I should put my Android GCP Credentials Client ID or GcP Web Credentials Client ID for the client_id. Anyone has a clue?

1 Like

OK. This is very strange. I put the gpgs.get_id_token() elsewhere in the code to see what happens (e.g. when I click somewhere), and the ID token was valid there!

I guess it was some kind of need to wait for the id to be retrieved, or maybe the code above shows a call that is made too early to the get_id_token function.

The strange thing, however, is that even if I delete all cache and data or reinstall the app, or even remove my app from my Google account privacy settings and then reconnect, I seem to get an id_token and not nil. I hate bugs/situations I can’t reproduce.

I’m a bit surprised that gpgs.get_id_token() returns nil when called from the sign-in callback. All of the data should be there to get the token. Please create a bug report on GitHub. Make sure to include a minimal project where the issue can be reproduced.

The issue won’t reproduce now, so I can’t create a minimal project for a bug report. Thanks for the answer though.

1 Like