typebot.io icon indicating copy to clipboard operation
typebot.io copied to clipboard

Issue authenticating to Google Sheets

Open StariMarco opened this issue 2 years ago • 3 comments

Hi, I'm experiencing an issue with the Oauth 2.0 authentication to Google Sheets.

I'm using the self-hosted version of Typebot, which is hosted on Fly.io using Docker.

Everything works correctly initially when connecting my Google account through the Typebot builder, but after a day, it stops working and returns the following error:

(I have replaced the "refresh_token" value with <token>)

	"response": {
		"config": {
			"method": "POST",
			"url": "https://oauth2.googleapis.com/token",
			"data": "refresh_token=<token>",
			"headers": {
				"Content-Type": "application/x-www-form-urlencoded",
				"User-Agent": "google-api-nodejs-client/8.8.0",
				"x-goog-api-client": "gl-node/18.16.0 auth/8.8.0",
				"Accept": "application/json"
			},
			"body": "refresh_token=<token>",
			"responseType": "json"
		},
		"data": {
			"error": "unauthorized_client",
			"error_description": "Unauthorized"
		},
		"headers": {
			"alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000",
			"cache-control": "no-cache, no-store, max-age=0, must-revalidate",
			"connection": "close",
			"content-encoding": "gzip",
			"content-type": "application/json; charset=utf-8",
			"date": "Mon, 26 Jun 2023 17:47:15 GMT",
			"expires": "Mon, 01 Jan 1990 00:00:00 GMT",
			"pragma": "no-cache",
			"server": "scaffolding on HTTPServer2",
			"transfer-encoding": "chunked",
			"vary": "Origin, X-Origin, Referer",
			"x-content-type-options": "nosniff",
			"x-frame-options": "SAMEORIGIN",
			"x-xss-protection": "0"
		},
		"status": 401,
		"statusText": "Unauthorized",
		"request": {
			"responseURL": "https://oauth2.googleapis.com/token"
		}
	},
	"config": {
		"method": "POST",
		"url": "https://oauth2.googleapis.com/token",
		"data": "refresh_token=<token>",
		"headers": {
			"Content-Type": "application/x-www-form-urlencoded",
			"User-Agent": "google-api-nodejs-client/8.8.0",
			"x-goog-api-client": "gl-node/18.16.0 auth/8.8.0",
			"Accept": "application/json"
		},
		"body": "refresh_token=<token>",
		"responseType": "json"
	},
	"code": "401"
}

I have even tried to make the google sheet document publicly accessible (with editor access), but I get the same error.

Please let me know if any further information is required to address this issue. Thank you!

StariMarco avatar Jun 26 '23 18:06 StariMarco

So you need to remove your Google credentials in the editor, connect it again, and then it works again after ~1 hour?

baptisteArno avatar Jun 27 '23 05:06 baptisteArno

When I remove my Google credentials and connect it back it immediately starts working again. Then after some time, usually the day after, it stops working and it gives me that code 401 error.

StariMarco avatar Jun 27 '23 06:06 StariMarco

So the issue is that you are unauthorized to refresh the token.

I found this: https://stackoverflow.com/questions/13871982/unable-to-refresh-access-token-response-is-unauthorized-client

Could that maybe help you? 🤔

baptisteArno avatar Jun 28 '23 07:06 baptisteArno