REST based captcha generating microservice
Consists of the following types:
- Request captcha using one of the methods
- Response body is the raw body of the captcha (image/sound) and Captcha Id will be provided in
X-Captcha-Session-Id
header - Answer can be verified using the
/verify
endpoint providing a JWT token - JWT token can be used to confirm authenticity on server side or client side with
/verify
endpoint
Get a random captcha from all the methods supported
Header: X-Captcha-Session-Id
- contains the captcha id
Body is raw content of the captcha (image/sound)
Get image captcha
Header: X-Captcha-Session-Id
- contains the captcha id
Body is raw image in png format
Get math challenge which gives a math equation
Header: X-Captcha-Session-Id
- contains the captcha id
Body is raw image in png format
Verify captcha answer. A JWT token is returned if the answer is correct (200
status code), else 401
status code is returned
Can be used server side to validate the verification
PORT= Application port
JWT_SECRET= JWT signing secret
HOST= Hostname to use in JWT token
PROMETHEUS_SECRET= Prometheus secret (Use with header
Authorization: Bearer <PROMETHEUS_SECRET>)
RATE_LIMIT_DURATION= Rate limit duration in seconds
RATE_LIMIT_POINTS= Rate limit points for given duration
REDIS_HOST= Redis host
REDIS_PORT= Redis port
REDIS_PASSWORD= Redis password
REDIS_DB= Redis database
REDIS_USERNAME= Redis username
CAPTCHA_TIMEOUT= Captcha timeout in seconds
docker run -d --name captcha-microservice --env-file app.env -p 5555:5555 crossphoton/captcha-microservice:v1.0.0
There are 4 components to deploy:
- Redis - For session id to solution mapping
- Secrets - For configuration
- Captcha Microservice - The main service
- Ingress - For exposing the service
For ingress make sure that ingress is configured. (Use nginx ingress for digital ocean)
- Clone repository
- Run
npm install
- Run
dotenv -e app.env -- npm start
- Prometheus :
/metrics
endpoint with proper authorization can be used to collect metrics - Logging : is done using winston.
- Shutdown management : done using lightship
MIT License