Skip to content

Start and stop the i-refactory OAuth2 server

In this section we explain how to start and how to stop the i-refactory Oauth2 server.

General approach

Starting an i-refactory OAuth2 server

The server is a NodeJS application which can be started on the command prompt from the root directory of the application.

cd <root-application-directory>
export NODE_PATH=./
node index

In the above scenario the application is started and the assumption is made that a config.json file exists in the root application directory. The configuration file is read and the server is started. The config file contains the server configuration and the users/applications which can make requests for a token. If new applications, users should be granted access you need to edit the config file and stop/start the server.

Stopping the server

If the server is running in your terminal simply press Ctrl-C.

Starting the server as a background service

There are many ways to start the server as a background service and there are many process managers.
Perhaps the most easiest one is to create a docker container and start the service with a service manager for docker containers.

Docker example

Build an image

The i-refactory server is shipped as a zip file with the relevant node_modules already downloaded.
Creating a docker image is straightforward.

Example Dockerfile:

FROM node:14-alpine AS dependencies
RUN apk update && \
    apk add --no-cache tzdata
ENV TZ Europe/Amsterdam

# Create app location
WORKDIR /app

# Copy code
COPY . .

# set the node path so modules can properly be required
ENV NODE_PATH=./
  • The alpine node docker image is the base image that is needed to run NodeJS.
  • We install tzdata to set the server to the appropriate timezone.
  • The content of the i-refactory server source files is copied to /app.
  • The NODE_PATH is set to ./

To build the image open a terminal:

cd <directory where you stored the i-refactory server code>
create a file Dockerfile with the example content as shown above.
docker build -t  <image>:<tag> ./

Start a container with docker-compose

The i-refactory server can be started with docker-compose.

Example docker-compose file:

version: "3.8"
services:
  i-refactory-oauth2:
    image: <your image>
    volumes:
      - <file-path-to-config-file>/config.json:/app/config.json:ro
      - <file-path-to-crypto-keys>:/app/crypto:ro
    ports:
      - 3003:3003
    # Needed to respond to prompts in the console
    stdin_open: true
    tty: true
    environment:
      - NODE_ENV=production
    command:
      node index
networks:
  default:
    external:
      name: i-refactory-net
  • Uses docker 3.8 spec
  • Defines a service with name i-refactory-oauth2 for the image that was build with the Dockerfile. You need to replace .
  • With the volumes section you need to pass the config.json file and the crypto files.
  • Port mapping for the service.
  • A default network is created. Rename if needed.

To start the server with docker-compose:

Create a file docker-compose-irefactory-oauth2.yml and store your compose config in it.
docker-compose -f ./docker-compose-irefactory-oauth2.yml up -d

Start the server on Windows with NSSM

See the detailed description in Operating Irefactory Server