AI Agent Setup with n8n - Google Drive OAuth in Local Network without Domain/URI
If you are having issue setting up an OAuth credential in n8n due to invalid URI, this article outlines how you can use nip.io to workaround the restriction even if you only have a local IP.
One of the great things you can do with an AI agent is to connect it to all your documents on the cloud. This opens up a ton of possibilities, such as asking it for a meeting summary, or getting it to book an event in your calendar. In this article, we are using a localized environment to develop our AI Agent. The environment includes Ollama, Postgres, n8n, and Qdrant. The scope today is to focus on connecting Google Drive to our localized environment using OAuth so that any new or changing documents are fed into Qdrant as datasets. For most parts, n8n has a very well written guide and a video on how to get this rolling.
n8n Guide: "Google: OAuth2 single service"
Video tutorial: Getting Google OAuth Credentials for n8n
However, as we are developing locally, there is a good chance that we will not be able to satisfy Google’s requirement to use a proper URI when creating the OAuth web application credential in Google Cloud. The error message that we will see are:
Invalid Redirect: must end with a public top-level domain (such as .com or .org).
Invalid Redirect: must use a domain that is a valid top private domain.
Also shown as a screenshot here.
Of course, to resolve this issue properly, we could:
Obtain a domain and point it to our server.
Setup ngrok service in our dev environment.
Either of these options would do. But not only will they take some time and effort (and some cash if we don’t already own a domain), they will also expose our application to the web.
A quick workaround is to utilize the nip.io project. It’s a nifty DNS service that translates a customized URI into our local IP address. In short, it allows us to create an address such as “192.168.10.101.nip.io” that resolves into “http://192.168.10.101”. It’s pure magic! Even better, there’s no account to create, no configuration to fill out, nothing! There are just a few steps to make this work.
We are going to assume the IP address where the n8n resides locally is “192.168.10.101”. Yours will very likely be different.
For n8n running as a docker container, we will need the following environmental variable
-e WEBHOOK_URL=http://192.168.10.101.nip.io:5678
Here is an example of a docker run command.
docker run -it --rm \ --name n8n \ -p 5678:5678 \ -v ~/.n8n:/home/node/.n8n \ -e N8N_PORT=5678 \ -e WEBHOOK_URL=http://192.168.10.101.nip.io:5678 \ n8nio/n8n
If docker compose is used, we will need to insert the WEBHOOK_URL into our environment variable section.
services: n8n: image: n8nio/n8n:latest networks: ['demo'] environment: - DB_TYPE=postgresdb - DB_POSTGRESDB_HOST=pergola-postgres - DB_POSTGRESDB_USER=${POSTGRES_USER} - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD} - N8N_DIAGNOSTICS_ENABLED=false - N8N_PERSONALIZATION_ENABLED=false - N8N_ENCRYPTION_KEY - N8N_USER_MANAGEMENT_JWT_SECRET - N8N_SECURE_COOKIE - WEBHOOK_URL="http://192.168.10.101.nip.io:5678/" container_name: pergola-n8n restart: unless-stopped ports: - 5678:5678 volumes: - n8n_storage:/home/node/.n8n - ./n8n/backup:/backup - ./shared:/data/shared
If n8n is install on the system as an application, we will need to run the following commands
export WEBHOOK_URL=http://192.168.10.101:5678 pm2 restart n8n --update-env
Once we have set the WEBHOOK_URL, we should see the desired URL when creating a Google OAuth2 API credential in n8n.
Now we can paste that redirect URL back into Google Cloud without having it throw the errors.
There we go. Continue to follow the guide from n8n to complete the setup. Once we are done, the WEBHOOK_URL variable may be remove. Security-wise, even though we have technically authorized the nip.io domain, we have not shared with it the Client ID and Client Secret. Therefore it is still considered safe. This is a great way to quickly connect our Google Drive during developmental phase.