Trouble Getting the Auth0 Quickstart Tutorial for PHP to Work? Does Your Application Keep Redirecting to http://localhost:3000/?code=

This dev tip is brought to you by the developer of MoneyPhone: Personal Expense Tracking for Android and iOS. Consistently spend less than you earn each month and get your finances under control when you start monitoring your expenses with MoneyPhone!

Having trouble getting the official Auth0 quickstart tutorial for PHP to work? Keep getting redirected to http://localhost:3000/? Okay so here’s what may be going on:

First, this tutorial was meant to be run on a local development server, not in a production environment, thus all the localhost business. To fix this I had to do a few things. First, make sure you allow both your actual web facing callback url and localhost under Allowed Callback URLs on the Settings Page.

Second, you may need to go into your PHP scripts and set the $redirect_uri variable equal to a string containing your actual live web facing callback url, instead of the default getenv(‘AUTH0_CALLBACK_URL’). For example, see the picture below. I’ve commented out getenv(‘AUTH0_CALL_BACK_URL’) and hard-coded my actual callback url. You could also change the environment variable from the command line, but this would have been a lot of trouble for me as I’m using shared hosting to host multiple domains on one of my servers using Plesk. So try and simply hard code your callback url if you are having trouble, or change the environment variable from the command line if you want do things the correct and secure way.

Now just make sure to save your changes on the Auth0 Settings Page before you attempt to log in again, and that’s it!

 

topherPedersen