Auth service.
## !!! NOTHING TO SHOW, YET. WORK IN PROGRESS. !!!
---
auth-service is a tiny, re-usable authentication service to be used in any microservices' environment.
It is built on top of express , passport and JWT, therefore easy to extend and integrate.
- Registration of a user
- Login (and return a JWT token)
- Verify JWT token
- Logout
- Mark a user as deleted (cannot login anymore)
- Mark a user as undeleted (can login again)
- Verify the users email
- Send password reset email
- Password reset
- Return the user's profile
- Local database (MongoDB)
Current, only the local strategy is implemented (saving the user in the given MongoDB instance), but it should be pretty straightforward to extend auth-service with other authentication provider, such as:
- GitHub
- auth0
- saml
- oauth/oauth2
- DropBox
- OpenId
- ...
Just have a look at passports.js and the supported strategies.
$ docker run -it stefanwalther/auth-service
auth-service can be configured by the following environment variables:
General:
PORT
- The port to run the REST API (defaults to3010
).JWT_SECRET
- The secret used for JWT, defaults tofoo
'NODE_ENV
- Environment settings for the service (production
,development
ortest
), defaults todevelopment
.
Features:
ENABLE_AUDIT_LOG
- Enable or disable audit-log.REGISTRATION__DOMAIN_FILTER
- Filter domains for the registration process, can be a wildcard ('*'), a single domain (e.g. 'foo.bar') or a list of domains (e.g. 'foo.com,bar.com')
MongoDB:
Provide the connection to MongoDB either by providing a full connection string:
MONGODB_CONNECTION_STRING
- The full MongoDB connection string.
or by providing details of the connection:
MONGODB_DATABASE
- The MongoDB database, defaults todb
.MONGODB_HOST
- MongoDB host, defaults tolocalhost
.MONGODB_PORT
- MongoDB port, defaults to27017
.MONGODB_DEBUG
- Whether to use the Mongoose debug mode or not, defaults tofalse
.
NATS-Streaming:
NATS_STREAMING_HOST
- The NATS-Streaming host, defaults tolocalhost
.NATS_STREAMING_PORT
- The NATS-Streaming port, defaults to4222
.
Nodemailer: (e.g for sending an account verification message):
NODEMAILER_TRANSPORT
- The transport for Nodemailer (possible options:postmark
).
Depending on the transporter for Nodemailer the following options can be set:
Postmark:
POSTMARK_API_TOKEN
- Postmark`s Server API Token.
Nodemailer settings only need to be set if one of the following options are set to true
:
All endpoints are documented through OpenApi/Swagger using
http://localhost:3010/api-docs
Development environment
To start the development environment, go for
$ make up
This will essentially:
- Start MongoDB
- Start RabbitMQ (management UI available at: http://localhost:15672/)
- Start a server running the auth-service (http://localhost:3010)
- Watch changes and re-start the server
If you only want to run required services (e.g. MongoDB, RabbitMQ, etc.) and run the node.js process on your machine, then go for
$ make up-deps
Then start the server using
$ npm run start:watch
The API is available at http://localhost:3010
Run tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
Start MongoDB:
The following command will spin up a MongoDB instance to be used in the integration tests at port 27018 (to prevent conflicts with the default port).
$ npm run dc-dev-up
Then run one of the following options:
Run integration tests:
Spins up all required dependent services to run the integration tests and runs the integration tests:
$ make build-run-integration-tests
Run unit tests:
$ make build-run-unit-tests
Update docs & readme
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
make gen-readme
Stefan Walther
MIT