Skip to content

This repository contains an application that works with a locally-running instance of FusionAuth, the authentication and authorization platform.

Notifications You must be signed in to change notification settings

FusionAuth/fusionauth-quickstart-javascript-express-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quickstart: Express.js API Resource Server with FusionAuth

This repository contains an application that works with a locally-running instance of FusionAuth, the authentication and authorization platform.

Setup

Prerequisites

You will need the following things properly installed on your computer.

  • Git: Presumably you already have this on your machine if you are looking at this project locally; if not, use your platform's package manager to install git, and git clone this repo.
  • node version 18 or later.
  • Docker: For standing up FusionAuth from within a Docker container. (You can install it other ways, but for this example we will assume you are using Docker.)

FusionAuth Installation via Docker

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:

You can log into the FusionAuth admin UI and look around if you want, but with Docker/Kickstart you don't need to.

complete-application

The complete-application directory contains a minimal app configured to authenticate with locally running FusionAuth.

Install the dependencies and run the app with

cd complete-application
npm install
npm run start

The app is now serving two api endpoints

You can login with a user preconfigured during Kickstart, [email protected] with the password of password and applicationId 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"
}'

Then make a request to the API using the returned token.

curl --cookie 'app.at=<your_token>' 'http://localhost:3000/make-change?total=1.02'

Further Information

Visit https://fusionauth.io/docs/quickstarts/quickstart-javascript-express-api for a step-by-step guide on how to build this API from scratch.

About

This repository contains an application that works with a locally-running instance of FusionAuth, the authentication and authorization platform.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published