Gatekeeper is open source, lightweight JWT-based authentication server for passwordless SMS phone verification. Users signup to your service by entering an SMS code, generating an access token which can be verified by your application without requiring database lookups. Persistent sessions are supported with refresh tokens.
Gatekeeper is open source, so feel free to host the project on your own servers. Alternatively, it's available as a Docker image.
A quick way to get up and running is to use the Gatekeeper Docker image,
which lives on Docker Hub at benmoose/gatekeeper.
You can configure the image with environment variables:
ENVIRONMENTshould be one of"production", "staging" or "test"DB_HOSTdatabase hostnameDB_PORTdatabase portDB_NAMEdatabase nameDB_USERusername of the database user to connect toDB_PASSWORDcorresponding password for the userAUTH_PUBLIC_KEY_PATHpath to the public key to verify tokensAUTH_PRIVATE_KEY_PATHpath to the private key to sign tokensAUTH_ACCESS_TOKEN_AUDIENCEvalue to populate theaud=claim in the JWTAUTH_ACCESS_TOKEN_ISSUERvalue to populate theiss=claim in the JWTTWILIO_ACCOUNT_SIDyour Twilio account SIDTWILIO_AUTH_TOKENyour Twilio auth tokenTWILIO_MESSAGING_SERVICE_SIDyour Twilio messaging service SID optionalTWILIO_MESSAGE_STATUS_CALLBACKURL to which Twilio will send SMS status webhook requests optional
Alongside Gatekeeper, you will need a database (e.g. Postgres) and a web server (e.g. Nginx).
The easiest way to set this up locally is to use docker-compose.
A minimal docker-compose.yml might look like this.
Note: Gatekeeper only supports postgres databases at the moment.
version: '3'
services:
db:
image: postgres
gatekeeper:
image: benmoose/gatekeeper
# Gatekeeper listens for incoming requests at unix socket `/var/tmp/shared-mount/gunicorn.sock`
volumes:
- "shared-mount:/var/tmp/shared-mount"
environment:
- "ENVIRONMENT=development"
- "DB_HOST=db"
- "DB_NAME=postgres"
- "DB_USER=postgres"
- "DB_PASSWORD="
depends_on:
- db
nginx:
image: benmoose/gatekeeper-nginx
volumes:
- "shared-mount:/var/tmp/shared-mount" # enable Nginx to send requests to Gatekeeper
ports:
- "8000:80" # expose to the host on port 8000
depends_on:
- gatekeeper
volumes:
shared-mount:Run docker-compose up to start the services.
Call curl http://localhost:8000/v1/health/ to check Gatekeeper is setup and running.
Gatekeeper listens for incoming requests at unix socket /var/tmp/shared-mount/gunicorn.sock so
when configuring your containers ensure that /var/tmp/shared-mount/gunicorn.sock
is shared between Gatekeeper and Nginx.
This lets the containers communicate. In the example above, this is achieved with volumes.
benmoose/gatekeeper-nginx is an Nginx image configured to use the unix socket at /var/tmp/shared-mount/gunicorn.sock.
You can see the configuration file in operations/nginx/nginx.conf.
Docker is recommended for local development.
With it installed, you can use the scripts in dev/ to run common commands
dev/test.sh [pytest-args]· run the test suite, all arguments are passed through to pytestdev/manage.sh [command]· run a Django management commanddev/fmt.sh [--check]· lint Python codedev/psql.sh· run psql on the DB container, the DB container needs to be running for this command to work
To run a local version of the production app, run
$ docker-compose upThe local server signs and verifies JWTs using the RSA keys in __fixtures__/.
Configure the local server (e.g. Twilio credentials) by setting the relevant variables in .local.env.
Take care not to commit changes to this file though!
The local server listens at http://localhost:8000.
You can set a different port by setting the SERVICE_PORT environment variable.
$ SERVICE_PORT=4040 docker-compose up