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

How to apply Google API key restrictions? #720

Open
georgjaehnig opened this issue Jan 21, 2023 · 5 comments
Open

How to apply Google API key restrictions? #720

georgjaehnig opened this issue Jan 21, 2023 · 5 comments
Labels

Comments

@georgjaehnig
Copy link
Contributor

georgjaehnig commented Jan 21, 2023

To my knowledge, I can only set 1 Google API key with $egMapsGMaps3ApiKey, which then is used both for

  • gecoding
  • map display.

Now I'd like to create a key restriction in Google, to prevent that other people use my key (and then generate quota on my bill). Google offers me among others to restrict by

  • HTTP referrers (web sites)
  • IP addresses (web servers, cron jobs, etc.)

image

These are radio buttons so it seems I can only pick one of them at the same time.

  • So when I pick HTTP referrers (and set it to my website), then the map can get displayed – but the geocoder, operating from my server cannot.
  • And when I pick IP addresses (and set it to my server), then the geocoder can work – but the map display does not work anymore because my website visitors have many different IPs each.

So how can I meaningfully restrict my Google API key? I thought about creating 2 (one for map display, one for geocoder), but Maps seems to accept only one in the settings.

@JeroenDeDauw
Copy link
Member

Maps indeed only support one Google API key

@georgjaehnig
Copy link
Contributor Author

OK. So you don't restrict your API key at all on your wikis?

@JeroenDeDauw
Copy link
Member

JeroenDeDauw commented Jan 21, 2023

This was implemented in 2009, and the API keys have undergone some changes since then. Personally, I am not using Google Maps anywhere, so I am not up to speed.

Your use case sound valid to me. Maps simply does not support it. So I do welcome PRs that add the feature.

@georgjaehnig
Copy link
Contributor Author

georgjaehnig commented Jan 21, 2023

Alright. I could implement then sth. like this. The API key could still either be set as a string:

$egMapsGMaps3ApiKey = 'MY_API_KEY';

or now also as an array:

$egMapsGMaps3ApiKey = [
  'Geocoding API' => 'MY_GEOCODING_API_KEY'
  'Maps JavaScript API' => 'MY_MAPS_JAVASCRIPT_API_KEY'
];

Makes sense?

@JeroenDeDauw
Copy link
Member

I would rather keep the setting always be a string and instead have a new egMapsGoogleGeocodingApiKey setting. That one could then (internally) default to egMapsGMaps3ApiKey if it is not set.

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

No branches or pull requests

2 participants