This repository provides an example server implementation for FusionAuth Web SDKs. FusionAuth Web SDKs can be utilized in one of two ways:
If you opt for hosting your own server, this repository will serve as an example. The provided example is in JavaScript and utilizes Express. If you opt to implement your own server you are free to use any technology stack as long as it meets the server code requirements.
To get started, follow these steps:
npm install
.npm run start
.You should observe the console output FusionAuth example server listening on port 9000
.
The endpoints described below serve as a summary of requirements and expected behaviors of each endpoint. For additional details on these endpoints you can reference the Hosted Backend documentation.
Your server must have the following endpoints:
GET /app/login
This endpoint must:
redirect_url
from the client app to state
./oauth2/authorize
with a redirect_uri
to /app/token-exchange
GET /app/callback
This endpoint must:
Call
/oauth2/token
to complete the Authorization Code Grant request. The code
comes from the request query parameter and
code_verifier
should be available in the secure HTTP-only cookie, while
the rest of the parameters should be set/configured on the server
side.
Once the token exchange succeeds, read the app.at
from the
response body and set it as a secure, HTTP-only cookie with the same
name.
If you wish to support refresh tokens, repeat step 2 for the
app.rt
cookie.
Save the expiration time in a readable app.at_exp
cookie. This value should be represented as seconds since the epoch.
And save the app.idt
id token in a readable cookie.
Redirect browser back to encoded url saved in state
.
GET /app/register
This endpoint is similar to /login
. It must:
redirect_url
from the client app to state
./oauth2/register
with a redirect_uri
to /app/callback
GET /app/me
This endpoint must:
app.at
from cookie and use as the Bearer token to call /oauth2/userinfo
GET /app/logout
This endpoint must:
app.at
and app.rt
secure, HTTP-only
cookies.app.at_exp
and app.idt
secure cookies./oauth2/logout
POST /app/refresh
(optional)This endpoint is necessary if you wish to use refresh tokens. This endpoint must:
Call
/oauth2/token
to get a new app.at
and app.rt
.
Update the app.at
, app.at_exp
, app.idt
, and app.rt
cookies from the
response.
This library may periodically receive updates with bug fixes, security patches, tests, code samples, or documentation changes.
These releases may also update dependencies, language engines, and operating systems, as we\'ll follow the deprecation and sunsetting policies of the underlying technologies that the libraries use.
This means that after a dependency (e.g. language, framework, or operating system) is deprecated by its maintainer, this library will also be deprecated by us, and may eventually be updated to use a newer version.