1.0.2 • Published 5 years ago

authserver-ez v1.0.2

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

authserver-ez

DESCRIPTION

a simple authentication server written in node js that has some similar functionality with SuperLogin. Authserver-ez handles your authentication enabling you to easily register new users, log them in, and log them out. Authserver-ez uses CouchDB for storing users and can be synced with a local PouchDB instance to also store whatever data you want and enable offline functionality. When a new user is registered a new database is created for them. Secondary users can also be created that will use the same database as a parent user so you can share your database. CouchDB also has fauxton which is a user interface for managing your CouchDB instance which comes in handy during development or if you are having issues. Authserver-ez uses redis to store the session information for all users and in this way allows multiple users to use authserver-ez without overwriting other users' session data. Authserver-ez also has routes for handling emails like password reset and email confirmation links. You could utilize the same logic to send other emails for different purposes and I would be willing to add more kinds of email routes if anybody would like me to do so.

to use this authserver-ez you must have nodejs and npm, and CouchDB and Redis instances to connect to either locally or in the cloud.

REQUIREMENTS

nodejs (I use version 12.4.0)

npm (I use version 6.9.0)

couchDB

redis

sendGrid account or another email service that works with nodemailer

AUTHSERVER-EZ INSTALLATION INSTRUCTIONS

npm install authserver-ez

COUCHDB INSTALLATION INSTRUCTIONS

Windows: go to https://couchdb.apache.org/ click on a download of your choice (though you should use the latest stable release) and follow the installer prompts

Linux(Debian): follow the instructions here: https://linuxize.com/post/how-to-install-couchdb-on-ubuntu-18-04/ and make sure to add your login credentials to the couchDB connection string

for more information on couchDB: https://couchdb.apache.org/

REDIS INSTALLATION INSTRUCTIONS

Windows: redis is cannot be easily installed on Windows like it can on Linux, so instead I am using Docker Desktop for Windows and an official redis container image. To do this first create an account at Docker Hub www.hub.docker.com then download Docker Desktop for Windows from Docker Hub. Then use command:

    docker pull redis

(this will grab the latest image) then use command:

    docker run -d --name <THENAMEYOUWANT> --publish 6379:6379 redis

(this command runs a detached container with the redis image you pulled, names the container what you want and maps port 6379 of the container to port 6379 of the host computer which is where authserver-ez will be looking for the redis instance. when not in use just use command:

    docker stop <the name of the container>

and then to start use command:

    docker start <the name of the container>

to delete the container stop it and use command:

    docker rm <the name of the container>

Linux(Debian): make sure your packages and computer are up to date with command:

sudo apt-get update

and then:

sudo apt-get upgrade

then install redis with command:

sudo apt-get install redis-server

for more information on redis: https://redis.io/

NODEJS AND NPM INSTALLATION INSTRUCTIONS

Windows: go to https://nodejs.org/en/ pick a download and follow the installer prompts.

Linux(Debian): make sure your packages and computer are up to date with command:

sudo apt-get update

and then:

sudo apt-get upgrade

then use command:

sudo apt-get install nodejs

to install nodejs.

then use command:

sudo apt-get install npm

to install npm

for more information on nodejs and npm: https://nodejs.org/en/

SENDGRID INSTRUCTIONS

Go to https://sendgrid.com/ and register for an account. The username and password you choose will be the username and password you need to set for your sendGrid credentials in authserver-ez

AUTHSERVER-EZ USAGE

Require authserver-ez, make an options array, create a variable for authserver-ez and pass it the options array

    var Authserver = require('./authServer.js');

    var options = {
        redis: {
            host: ip-or-localhost,
            port: port-redis-runs-on
        },
        couchDB: couchdb-connection-string,
        sendGrid: {
            username: sendGrid-username,
            password: sendGrid-password
        }
    };
    var authserver = new AuthServer(options);

Connect to authserver-ez on port 3000 if you are using authserver-ez locally it will be http:localhost:3000 and if you are hosting it somewhere like example.com then the connection string would be http:example.com:3000 or if it you have just an IP like 196.96.0.1 then the connection string would be http:196.96.0.1:30000 To use authserver-ez you just need to send requests to the routes that have been set up like /register to register a user. This means that you can have it connected to pretty much any kind of application or website as long as it can make http requests.

EXAMPLE REQUEST

Written in Angular2/TypeScript

async onLogin() {

const uname = this.loginForm.controls.username.value;

const pword = this.loginForm.controls.password.value;

const header = new HttpHeaders();

header.append('Content-Type', 'application/json');

await this.http.post('http://localhost:3000/login', {
  username: uname,
  password: pword
},
  {headers: header})
    .subscribe(res => {
      console.log(res);
      this.authService.login();
      this.router.navigateByUrl('/menu/home');
    }, (err) => {
      console.log('error loggig in with authServer');
      console.log(err);
      this.failToast();
    });

  }

ROUTES

/register register new user

/login login user

/logout logout user

/forgotPasswordResponse sends a password reset email to user

USER FIELDS

_id user's id (created for you on register)

name user's name

username user's username

password user's password

email user's email

userDB user's database name (created for you on register)

parent used in creating secondary users on a parent's database (send 'NONE' in request to register a new user with new database)

level used for permissions (primary users have level 'ADMIN' on register)

confirmed used to check if email has been confirmed

status can be used to determine status of an account especially if you want to do subscription based accounts (on register status is set to 'VALID')