This repository contains a Laravel API that works with a locally-running instance of FusionAuth, the authentication and authorization platform.
You will need the following things properly installed on your computer.
- PHP 8.1+: This quickstart was built using PHP 8.1 and tested with PHP 8.2 as well. It may work on different versions of PHP, but it has not been tested.
- Composer to install PHP dependencies.
- Docker: The quickest way to stand up both FusionAuth and Laravel. Ensure you also have docker compose installed.
- (Alternatively, you can Install FusionAuth Manually).
The root of this project directory (next to this README
) are two files: a Docker compose file and an environment variables configuration file. Assuming you have Docker installed on your machine, you can stand up FusionAuth up on your machine with:
docker compose up -d
The FusionAuth configuration files also make use of a unique feature of FusionAuth, called Kickstart: when FusionAuth comes up for the first time, it will look at the Kickstart file and mimic API calls to configure FusionAuth for use when it is first run.
NOTE: If you ever want to reset the FusionAuth system, delete the volumes created by docker-compose by executing
docker-compose down -v
.
FusionAuth will be initially configured with these settings:
- Your client Id is:
e9fdb985-9173-4e01-9d73-ac2d60d1dc8e
. - Your client secret is:
super-secret-secret-that-should-be-regenerated-for-production
. - Your admin username is
[email protected]
and your password ispassword
. - Your teller username is
[email protected]
and your password ispassword
. - Your customer username is
[email protected]
and your password ispassword
. - The FusionAuth instance is located at
http://localhost:9011/
.
You can log into the FusionAuth admin UI and look around if you want, but with Docker/Kickstart you don't need to.
The complete-application
directory contains a minimal Laravel app configured to authenticate with locally running FusionAuth.
Install the dependencies via Composer:
cd complete-application
composer install
./vendor/bin/sail up -d
The app is now serving two api endpoints:
- http://localhost/api/make-change - this endpoint calculates the change to make from a given total.
- http://localhost/api/panic - this endpoint simulates notifying the police of an incident.
You can log in with a user preconfigured during Kickstart, [email protected]
with the password of password
, by calling:
curl --location 'http://localhost:9011/api/login' \
--header 'Authorization: this_really_should_be_a_long_random_alphanumeric_value_but_this_still_works' \
--header 'Content-Type: application/json' \
--data-raw '{
"loginId": "[email protected]",
"password": "password",
"applicationId": "e9fdb985-9173-4e01-9d73-ac2d60d1dc8e"
}'
You can take the token from the response and then call one of the endpoints listed above by calling:
curl --cookie 'app.at=<your_token>' 'http://localhost/make-change?total=5.12'
or
curl --cookie 'app.at=<your_token>' --request POST 'http://localhost/panic'
Visit https://fusionauth.io/docs/quickstarts/quickstart-php-laravel-api for a step-by-step guide on how to build this Laravel API from scratch.