FaridSafi / react-native-google-places-autocomplete

Customizable Google Places autocomplete component for iOS and Android React-Native apps
MIT License
2k stars 852 forks source link

Avoid hardcoding Google API Key #612

Closed cmatthews555 closed 4 years ago

cmatthews555 commented 4 years ago

Describe the problem

I want to remove the google API key from the source code of my app. Is there another way to get this key to your library? For my other APIs I am using AWS API Gateway to proxy the requests and on the way through it appends the appropriate API key. Can I follow that pattern with this library?

Reproduction - (required - issue will be closed without this)

The library works fine with the hardcoded API key, I'd like to avoid that.

Additional context

If you are using expo please indicate here:

Add any other context about the problem here, screenshots etc

I love this library, thanks for taking the time!

bell-steven commented 4 years ago

You should be able to do this using the requestUrl prop. See the signature here.

cmatthews555 commented 4 years ago

I understand what you're saying and I tried it out. That worked for me, thanks!

dftaher commented 3 years ago

If we use this solution, we need a way to whitelist the request made by the RN app. One way to do this is to use bearer token in the header, however the library does not support passing the token. Is there any other option that you recommend?

If you think passing token in header is viable solution, should I submit a PR?

KrisLau commented 2 years ago

Might be helpful to anyone else who is trying to implement this: https://www.farhansayshi.com/post/hiding-api-keys-on-react-native-in-10-minutes-with-api-gateway/#adding-proxy-url-to-frontend

derekmurawsky commented 1 year ago

Might be helpful to anyone else who is trying to implement this: https://www.farhansayshi.com/post/hiding-api-keys-on-react-native-in-10-minutes-with-api-gateway/#adding-proxy-url-to-frontend

Though this technically solves the problem of hard coding the api key in the app, you still need to authorize api requests to this proxy somehow. The correct (IMO) way to handle this kind of semi-sensitive key is by supporting the native ways of locking it down in both IOS and Android. See this link for guidance https://github.com/FaridSafi/react-native-google-places-autocomplete/issues/787#issuecomment-1013358580

manasadepu commented 5 months ago

You should be able to do this using the requestUrl prop. See the signature here.

@bell-steven Would like to implement this as well. But I cant seem to understand how to use that signature.