N8N can't use Google OAuth2

Problem:

Trying to add a Gmail node but adding the Google client credential fails with this error?

You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy for keeping apps secure.

Error 400: invalid_request

Request details: redirect_uri=n8n.yourdomain.com/rest/oauth2-credential/callback flowName=GeneralOAuthFlow

In my case, the problem was a wrongly set FQDN env variable in my Coolify n8n service.

Solutions:

Coolify edit SERVICE_FQDN_N8N variable
  1. If running n8n via Coolify: make sure the SERVICE_FQDN_N8N includes the protocol (https://) part.
    So, your SERVICE_FQDN_N8N should be https://n8n.yourdomain.com instead of n8n.yourdomain.com
    Note that in my case, I couldn't edit the SERVICE_FQDN_N8N env variable, so I simply deleted and added it again.
  2. Make sure the Callback URI in your Google Auth Platform client matches the one from n8n (in my case, in Google it had an extra trailing slash that I had to remove).
    Make sure your callback is:
    https://n8n.yourdomain.com/rest/oauth2-credential/callback and not
    https://n8n.yourdomain.com/rest/oauth2-credential/callback/