Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
703 views
in Technique[技术] by (71.8m points)

geolocation - Concealing API key in Front End javascript

I have a web application that requires user location.

I am using the Google GeoLocation API. Because this API returns the GeoLocation of the caller, I must call from the client side, which means I must give the client my API key. Obviously this opens me and my API key to potential abuse.

It would be ideal to have the backend make the actual call to the GeoLocation API, but I don't understand how that could be done, given the nature of the GeoLocation API.

Therefore, is there a way around this that would allow me conceal my Google API key, yet still allow the client to submit the request to the GeoLocation API?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should whitelist your website domain for your production key so that it can only be called on your website.

Also setup API key restriction to only Map JavaScript API.

It can be done under credential tab of APIs and Services in your GCP console.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...