LaraCrafts / laravel-geo-routes

GeoLocation restricted routes for Laravel
MIT License
111 stars 5 forks source link

Does this work on local machine (localhost) ? #28

Closed UchennaPrudensia closed 5 years ago

UchennaPrudensia commented 5 years ago

Was wondering if this works on local machine. I am using vagrant. I just did a fresh install and tried the sample code below.

Route::get('/', function () { return view('welcome'); })->allowFrom('us');

then I get a 401|unauthorized. Did i miss something?

nerg4l commented 5 years ago

The problem with local usage is with the 127.0.0.1 IPv4 and ::1 IPv6 as the script can not tell the location of that address. But this is something which should be investigated and fixed if this is an issue.

axlon commented 5 years ago

@nerg4l maybe we should allow localhost by default? I can't really think of a use case where you wouldn't want to allow it

nerg4l commented 5 years ago

@axlon Maybe this can be handled in a better way as stevebauman/location already has a basic implementation.

https://github.com/stevebauman/location/blob/d4366ba9815c1e076fba9eb1ca0a52ccd8e78550/src/Config/config.php#L78-L96

axlon commented 5 years ago

Ah yes, because when using a development box, it isn't said that you are accessing the site from localhost.

This sounds like a good way to implement this

axlon commented 5 years ago

@UchennaPrudensia as @nerg4l said you can use the testing tools available in stevebauman/location which this package depends on.

I think in time we will implement our own testing, but it's not a priority right now since the above is available.

Hope this helps.

UchennaPrudensia commented 5 years ago

@axlon thank you so much. Does this mean i have to test each ip address from different countries one after another or can i just add the different ip's in an array? and can i still do?

Route::get('/', function () {
return view('welcome');
})->allowFrom('us');
UchennaPrudensia commented 5 years ago

@axlon after changing the ip in the config folder, the application still runs as normal. Its not blocking. Please take a look. I followed all the steps as mention earlier.

   /*
|--------------------------------------------------------------------------
| Localhost Testing
|--------------------------------------------------------------------------
|
| If your running your website locally and want to test different
| IP addresses to see location detection, set 'enabled' to true.
|
| The testing IP address is a Google host in the United-States.
|
*/

'testing' => [

    'enabled' => true,

    'ip' => '13.107.184.8',

],

From my understanding my server sees this ip address as my new ip and should deny access right? Please, can some one elaborate more of what's going on behind the scenes. Thank you @axlon and @nerg4l for your help.

yak0d3 commented 5 years ago

Hello there,

I know that this is bit late, but @nerg4l has already spoke of most of the things i wanted to say.

The geo-routes package depends on the stevebauman/location package to retrieve the country code from the client IP in the middleware and then determine if the country is allowed or not. Take a look here.

The solution proposed by @nerg4l might not work because at the moment the geo-routes package retrieves the IP manually and passes it to the get method of the Location class, which in fact is not a very good practice IMHO because the location package is configured to work with a testing IP whenever in localhost.

I hope that this is what you're asking about and hope that you find my comment helpful 😄.

UchennaPrudensia commented 5 years ago

Hi @yak0d3 , thank you for taking the time to explain. I really appreciate 💯. I understand now. I will test the application on a live server.

axlon commented 5 years ago

Hi @UchennaPrudensia, I just tagged version 0.2.1 which should fix the problems you are having. Faking your IP through the method we talked about before should now work.

You can update the package by running the following command:

composer update laracrafts/laravel-geo-routes
UchennaPrudensia commented 5 years ago

@axlon , I just updated laracrafts/laravel-geo-routes and ran the application. The application still runs normally. It's not blocking the app. Thank you anyways. I will do a fresh install and try again. If it works I will update this post. Thanks!