Today’s topic is going to be about securing your Google Maps API key using the HTTP Referrer Restriction. It is obviously always best to keep your API keys hidden, but in any case, Google has provided another way to secure your API key. If you don’t have an API key, you can go ahead and follow this tutorial on creating a Google Maps API key.
First, log in to the Google Cloud Platform, and then head over to the API & Services > Credentials section as shown below:
Select the API key you want to add the restriction to:
Under ‘Application restrictions’, choose ‘HTTP referrers (websites)’, and then enter your domain in the format shown in the image below:
It takes about 5 minutes for things to update. Once updated, your Google Maps API key will now only be usable using your domain name only. Anyone else trying to use it will be denied access.
I hope this was useful, if you have any questions or need help with anything at all, please let me know using the comments section below.