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

iOS google version should be using native library instead of 'webclient' #20

Open
lzbikowski-opensource opened this issue Apr 22, 2020 · 9 comments

Comments

@lzbikowski-opensource
Copy link

First of all, thank you for the time you have put to 'resurrect' geocoder lib,

Saying that - I have noticed that it's using google web API instead of native iOS.

As a result, it's not possible to limit API key usage (and it can be stolen).
Do you have any plans to move to native ios API?

@timwangdev
Copy link
Owner

Hi @lzbikowski-opensource , it is using native API by default. "Force Google on iOS" options is for someone who needs consistent results across platforms.

@lzbikowski-opensource
Copy link
Author

lzbikowski-opensource commented Apr 22, 2020

Hi @timwangdev thanks for a quick reply.
that is what I meant - The force-google on iOS is using webapi.

As an example - if you generate Google API credentials for 'ios' the request will be rejected (I assume that through iOS sdk would be accepted as the bundle id is sent).
If you use 'webapi' key it works.

Does it make any sense ? :-)

The annoying part about 'native iOS' (not google) is lack of support for simultaneous requests...
I am exploring my options and considering to write a piece of native code/PR, but will try unimodules first...

@timwangdev
Copy link
Owner

timwangdev commented Apr 22, 2020

@lzbikowski-opensource I got your idea.

Using native API requires embedding or depending on Google Maps SDK, which may be not the direction I'm looking for. Since the package only using a geocoder service. And also, native SDK seems only providing reverse geocoding.

API keys restrictions could be an issue here, I will leave this open for discussion. Do you have any idea about this?

@timwangdev timwangdev reopened this Apr 22, 2020
@lzbikowski-opensource
Copy link
Author

Let me explore a bit and come back to discuss further

@lzbikowski-opensource
Copy link
Author

lzbikowski-opensource commented Apr 22, 2020

@timwangdev for reference:

It's indeed missing feature of SDK:
https://issuetracker.google.com/issues/35822639
However seems possible as per comment within this ticket (not tested):
"We can call the API directly in the app without using the SDK. However, there is no document to tell where to put the bundle ID. In fact, you have to put bundle ID in the HTTP request headers with key = X-Ios-Bundle-Identifier*."

"The important bit is to populate the X-Ios-Bundle-Identifier header.""

As per GoogleCloudPlatform/cloud-vision#16

Swift:

request.addValue(NSBundle.mainBundle().bundleIdentifier ?? "", forHTTPHeaderField: "X-Ios-Bundle-Identifier")
Objective-C:

[request addValue:[[NSBundle mainBundle] bundleIdentifier] forHTTPHeaderField:@"X-Ios-Bundle-Identifier"];

I will be exploring further and share any results here to help others.

@timwangdev
Copy link
Owner

According to FaridSafi/react-native-google-places-autocomplete#140 , and FaridSafi/react-native-google-places-autocomplete#526 , it seems that adding the Referer header will do the work.

@Alb93
Copy link

Alb93 commented May 6, 2020

Hi @timwangdev, how you can use Referer prop to get the Api Key not used outside your app? Can you post an example? Thank you

@bell-steven
Copy link

Hi @timwangdev, i'm the maintainer of react-native-google-places-autocomplete.
Just a heads up, adding a referrer header doesn't seem to work (we probably will have to roll back that PR). Using HTTP referrers can only be used with the JS SDK, otherwise you will receive this error: API keys with referer restrictions can not be used with this API.
If something changes i'll try and update here.

@timwangdev
Copy link
Owner

Hi @bell-steven, thank you very much for updating me about this. That actually makes a lot of senes.

I'll update the project about this limitation.

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

No branches or pull requests

4 participants