This is a simple REST API with authentication using JWT and Auth0 as OAuth provider.
npm install
Create a .env file in the root directory and add the following variables:
AUTH0_DOMAIN=
AUTH0_AUDIENCE=
npm run dev
The application can be run as a container. The Dockerfile is provided in the root directory. The container requires the same environment variables as mentioned above. It exposes a single port 3000.
To build run the following command:
docker build -t rest-api-with-auth .
To run the container:
docker run --name=rest-api-with-auth --rm=true -p 3000:3000 -e AUTH0_DOMAIN=... -e AUTH0_AUDIENCE=... rest-api-with-auth
Returns a welcome message.
Create a new policy. Provide the following parameters in the request body:
{
"name": "policy holder name",
"phone": "phone number",
"premium": "premium amount",
"suminsured": "sum insured amount"
}
This must be sent as an authenticated request. The JWT token must be sent in the Authorization header as a Bearer token.
The JWT token must be valid, have scope write:policy
and the audience must be as configured in the environment variable AUTH0_AUDIENCE
.