Skip to content

stefanwalther/auth-service

Repository files navigation

auth-service

Auth service.

CircleCI XO code style




## !!! NOTHING TO SHOW, YET. WORK IN PROGRESS. !!!

---

Summary

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.

Basic functionality

  • 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

Authentication Providers

  • Local database (MongoDB)

Social Authentication Providers

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
  • Google
  • Facebook
  • LinkedIn
  • OpenId
  • ...

Just have a look at passports.js and the supported strategies.

Installation

$ docker run -it stefanwalther/auth-service

Configuration

auth-service can be configured by the following environment variables:

General:

  • PORT - The port to run the REST API (defaults to 3010).
  • JWT_SECRET - The secret used for JWT, defaults to foo'
  • NODE_ENV - Environment settings for the service (production, development or test), defaults to development.

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 to db.
  • MONGODB_HOST - MongoDB host, defaults to localhost.
  • MONGODB_PORT - MongoDB port, defaults to 27017.
  • MONGODB_DEBUG - Whether to use the Mongoose debug mode or not, defaults to false.

NATS-Streaming:

  • NATS_STREAMING_HOST - The NATS-Streaming host, defaults to localhost.
  • NATS_STREAMING_PORT - The NATS-Streaming port, defaults to 4222.

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:

Usage

API

All endpoints are documented through OpenApi/Swagger using

http://localhost:3010/api-docs

Contribute

Development environment

Start the development environment

To start the development environment, go for

$ make up

This will essentially:

Only required services

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

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

Building docs

(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

About

Author

Stefan Walther

License

MIT