Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting nil for id token #46

Open
amireldor opened this issue Jul 28, 2023 · 5 comments
Open

Getting nil for id token #46

amireldor opened this issue Jul 28, 2023 · 5 comments

Comments

@amireldor
Copy link

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

@amireldor
Copy link
Author

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 🤷

@blendjam
Copy link

Still getting this issue inside the callback function

@britzl
Copy link
Contributor

britzl commented Dec 17, 2024

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

@britzl britzl reopened this Dec 17, 2024
@blendjam
Copy link

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.

@britzl
Copy link
Contributor

britzl commented Dec 21, 2024

DEVELOPER_ERROR

This seems relevant to your problem: https://stackoverflow.com/q/77466444

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants