/images/resources/tutorials/writing-clients/spa/spa-using-token-handler.jpg

Token Handler Installation

On this page

The token handler pattern enables single page applications to follow web security best practices. An SPA calls OAuth secured APIs via the token handler, which acts as a Backend for Frontend (BFF) for the SPA. The token handler consists of stateless API components and does not require any backend storage. API requests use HTTP-only cookies and there are no tokens in the browser.

Token handler components issue first-party cookies on behalf of the Single Page Application

Design Token Handler URLs

The first task is usually to design token handler base URLs, to provide endpoints for SPAs. You should consider both web development URLs and deployed systems.

Same Site Requirement

When designing URLs, make sure the SPA and BFF share the same parent site and use the same scheme (HTTP or HTTPS), so that cookies are same-site and the browser sends them reliably.

Web Development URLs

Start with development base URLs, which might use the following existing values, where a local SPA calls deployed APIs and an authorization server:

ComponentBase URLRuns Locally?
SPAhttp://localhost:3000Yes
APIhttps://api.example.comNo
Authorization Serverhttps://login.example.comNo

To use the token handler pattern there are no changes to the hosting of the APIs or the authorization server. Instead, add a new base URL that runs token handler components. Some example base URLs are summarized below.

ComponentBase URLRuns Locally?
SPAhttp://www.demoapp.example:3000Yes
Token Handlerhttp://api.demoapp.exampleNo
APIhttps://api.example.comNo
Authorization Serverhttps://login.example.comNo

It is possible to run a development setup that uses localhost URLs, but a more productive option for web developers is to switch to a domain based URL during development, such as http://www.demoapp.example:3000. Doing so enables web developers to externalize cookie security to a remote token handler.

Deployed URLs

It is usual to deploy the SPA and token handler to multiple stages of a deployment pipeline. The following table shows some example URLs:

StageSPA Base URLToken Handler Base URL
Developmenthttp://www.demoapp-dev.example:3000http://api.demoapp-dev.example
Testinghttps://www.demoapp-test.examplehttps://api.demoapp-test.example
Staginghttps://www.demoapp-staging.examplehttps://api.demoapp-staging.example
Productionhttps://www.demoapp.examplehttps://api.demoapp.example

Install the Curity Token Handler

Once there is a known token handler base URL, the next deployment step is to deploy the Curity product and use a license file to activate the token handler feature. The installation provides an administration user interface to configure the system and runtime endpoints that implement the security work.

Install the Curity product on any Linux based platform. Choose one of the options from the following sections to get up and running, and follow the links to tutorials to learn more about the installation mechanics for each platform.

The Install using Docker tutorial explains how to deploy the Curity product using Docker. Run the following example commands to set an admin password and quickly install the token handler on Docker on any Windows, macOS or Linux computer.

bash
12
export PASSWORD='zIf66A9Wz'
docker run -it -e PASSWORD=$PASSWORD -p 6749:6749 -p 8443:8443 curity.azurecr.io/curity/idsvr

Run the First Configuration

After deployment, log in to the Admin UI using the username admin and the configured password. The Admin UI URL is https://localhost:6749/admin for a local Docker deployment. It may have a different host name for other deployments. Next, configure and deploy the token handler so that the SPA can make OAuth and API requests. The First Configuration tutorial explains the configuration steps.

Join our Newsletter

Get the latest on identity management, API Security and authentication straight to your inbox.

Start Free Trial

Try the Curity Identity Server for Free. Get up and running in 10 minutes.

Start Free Trial