Laravel sanctum vue spa being blocked when using ip address - php

I know a lot has been documented on about laravel sanctum configuration to avoid blocked requests from your spa frontend, but something that is not quite clear and people aren't talking about, (maybe because it's already solved and documented somewhere I haven't seen).
My current configuration works with 127.0.0.1 but when I change both SESSION_DOMAIN and SANCTUM_STATEFUL_DOMAINS but when I change this for the ip address, this doesn't work.
I need to use a shared ip (192.168.45.23:8080), for me to test this on my mobile phone as well but I get the net::ERR_BLOCKED_BY_CLIENT.
What is configured so far
I have configured cors.php to allow the route I am visiting under paths
I have SESSION_DOMAIN set to that IP address
I have also set the SANCTUM_STATEFUL_DOMAINS to that IP address with the port as well.
I have also uncommented \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, under the kernel.php
What I am guessing:
Could it be if you not using localhost, you need to be running under https?
The reason I need to use this IP address,
I want to test my spa on mobile concurrently

When you run your Laravel server with this command,
php artisan serve
it will run on localhost and will only receive local connections.
If you want to access to your Laravel server from another machine inside your private network, I suggest you to run this command instead :
php artisan serve --host=0.0.0.0
If you want more detail about the difference between localhost and 0.0.0.0, please read this answer

What I am guessing:
Could it be if you not using localhost, you need to be running under https?
If you use LIVE site deployed on a hosting server, you can access to SPA on your phone.
It will be not handled on Laravel side.
If you wanna test SPA running on localhost using mobile phone,
List item
Run Ngrok to test your local development.
https://ngrok.com
List item
You can use Browserstack Localhost to test localhost on mobile(Emulator). https://www.browserstack.com/docs/local-testing

Related

Server data accessing from non local network without port forwarding

I'm using XAMPP server and I have my files in htdocs folder of XAMPP.
I had connected to my laptop using my mobile hotspot.
Can I access my files in XAMPP folder from another system which is not in same network i.e., can I access the files present in XAMPP folder from another another computer via internet
without router only by mobile hotspot?
Yes, it's possible to access the web server from an external network, depending on your current network configuration.
There are two simple solutions I think would suit you.
Configure your firewall if needed, enable port forwarding in your router settings to forward port 80 to the internal IP of the machine running your XAMPP-server.
If you're on a network in which you can't configure, I recommend checking out ngrok.com, which is a service where you can setup a public URL for your XAMPP-server. Works from any type of network, where you have internet-access, of course.
Note, alternative 2 is good for exposing a development-server, nothing I'd recommend for running a site in production.
Most network providers don't allow accessing the termials in the network.
If your provider does portforwarding and entering the public(!) IP of your hotspot should bei enough.

How to give on local to other pc access to your project in valet?

When I make a project in laravel I can give access with php artisan serve but if a make a normal project and make host with valet link the PHP artisan don't work because it's not a laravel project. How can i give access to local with valet ? For example i have project.dev and make 192.168.1.5:80 like in laravel.
You can use the valet park or valet link commands to be able to access your application locally.
For a local network, you will need to make sure your port is accessible if your're behind a firewall. You may need to setup port forwarding, as well, if NAT is involved.
Are you trying to make the project accessible to others on the internet? For this, you can use ngrok.
https://ngrok.com/
”I want to expose a local server behind a NAT or firewall to the internet.”

Set Laravel application online to whole LAN with domain name

I have developed a Laravel 5.4 application and now I want to put it "online" for everyone in my LAN and also set a local domain name to it, like somedomain.lan, for example. When I run php artisan serve --port=XXXX it starts the application on localhost port XXXX. Given that I'm running a Linux machine, how to make it available this service on port XXXX in such a way that my whole LAN, and only my LAN (not external internet), sees it and also give the domain name?
Open your command prompt, type "ipconfig", look for your ipv4 address. It should be 192.168.xxx.xxx.
Then php artisan serve --host=[your ipv4 address]
Make other computers connected to your network to connect to your application using your ipv4 address. Your ipv4 address define your computer address within current used network.
Not sure will work or not, but i do it this way and it works.
I would recommend you to use Laravel valet
With valet you can say:
Valet share
Then you will get a unique link that can be shared.
Super easy I use it everyday!
With artisan you can set the ip like this:
php artisan serve --host=503.246.895.41 --port=8125

Access to Laravel 5 app locally from an external device

I've looked for a solution in the web, but I've not found a solution yet.
I need to access to my Laravel 5 app from my iPhone, but I'm in develop, so I don't want to publish my app on a web server.
If you have a link to follow, that you assure it works, It's perfect for me.
Thank you!
If you're not bound to using Apache or nginx for some special reason and this is for development purposes only, you could serve the application using the PHP built-in server and artisan. It's by far the easiest thing to setup, and will only require you to run one command in the Laravel application directory:
php artisan serve --host 0.0.0.0
The default port it will be listening to will be 8000 to avoid any conflicts, so you can now access the application from your phone via the IP address of your computer:
http://192.168.1.101:8000
If you want to listen to another port (for example the default HTTP port of 80) you can pass that as a parameter, just make sure no other server is running on that port. So if you run this instead:
php artisan serve --host 0.0.0.0 --port 80
You can now access your application with just the IP address:
http://192.168.1.101
Its simple, first you have to run the server
php artisan serve --host 0.0.0.0
Then you need to know what`s your IP address, run this command to get IP:
In windows:
ipconfig
In Linux:
hostname -I
For example, my IP is: 192.168.1.68
Once you get your IP, then you have to go to this address on your mobile. Like:
192.168.1.68:8000
And that's it.
There are so many ways to do this.
Access your web via IP address from your iPhone, e.g. http://192.168.1.100/laravel
If your iPhone is jailbroken, you can edit iPhone's /etc/hosts file, the access your website via domain, e.g. laravel.com 192.168.1.100
Upload laravel app to web server and config it a test domain, e.g. dev.domain.com, or dev.domain.com:8080
If you can config your WiFi router, you can give your computer a "port forwarding" or set "DMZ"
Upload your website, and config "IP forbidden" roles, e.g. for Apache, edit your laravel's .htaccess file:
Deny from all
Allow from 180.159.251.175
You can use Laravel Homestead, an official pre-packaged Vagrant "box" to develop your project and access your local website from multiple machines within the same private network.
Here you can find more information about homestead and how to use it:
http://laravel.com/docs/5.0/homestead
And here a sample Vagrant private network setup:
http://docs.vagrantup.com/v2/networking/private_network.html
If you are having trouble using the accepted answers method, and you get page not found or similar errors, this is likely due to your firewall settings.
If
php artisan serve --host 0.0.0.0
doesn't seem to work.
Try php artisan serve --host 0.0.0.0 --port 80.
And access just using your IP address. For instance:
http://192.168.1.101

Instagram redirect-uri fails for localhost

I am writing a PHP app to fetch all my photos with Instagram using their API. However, what puzzles me is, I run the app on my hosted server it works perfectly fine and the same app running locally does not work.
Here are some points on the app workflow:
The user sees the homepage and he will be prompted with 'sign-in with Instagram'
User signs in with Instagram and authorizes the app.
Instagram redirects the user.
The app then makes a request for access_token and receives it.
Using the access_token, the app will send further requests for user media
The response is parsed and the links to the images are now provided to the user.
All the above mentioned process works fine on my hosted server but fails at 'Step 3.' and redirects user to home page of my app.
The problem is localhost being the redirect_uri. Does anyone have a solution to this problem to use the app locally?
P.S: I have registered two separate clients on Instagram: one for locally hosted development and the other on a web server.
Also, I have tried localtunnel. Did not help either.
I know its a very very very old Question. but for those who get to this page hoping a solution:
instagram currently does not allow to use something like localhost or myvhost.test in redirection url, whats more it requires the url to be certified (https).
so the only working solution I could find is using ngrok. you should download it from the url, open it and type a localhost virtual domain name along with a specific port number like ngrok http myLocalUrl.test/app 80, hit enter and it will gives you two temporary public links.
it will remain valid until you close the ngrok command line. you can direct the link to a specific port number and direct the port number to specific folder path of the application in your localhost.
the tutorials provided by ngrok is simple enough if you did not understand my hints.
I was dealing with this issue trying to develop an Instagram App using NodeJS/Express.
I got around this by using my computer's external local IP rather than localhost, which you can grep for. I assume you're on a *nix machine, so do a very simple (and crude)
$ ifconfig | grep inet
which will return you a few ip and MAC addresses, one of them being your external IP. However this is lousy because it means every time you switch IPs you'll have to update your application's redirect_url with Instagram as well as update any code that relies on it.
Thankfully, there exists services like no-ip that will basically provide free DDNS service to you, so you need simply register a hostname with them and then drop that into your DEV env code as well as your development client's redirect url and you're set to go!

Categories