1.0.7 • Published 4 years ago

avouch v1.0.7

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

Avouch, Complete Out of the Box Authentication server using Express

Node Version NPM Version Linux Build Windows Build

Currently Supported DB
Postgres
Currently Supported Encryption Standard
AES
Available in Future Versions
MySQL*
MariaDB*
MS SQL*
MongoDB*

Installation

$ npm install -g avouch

Quick Start

The quickest way to get started with authentication module is

Create the app:

$ avouch <new_project_name>

Open Project Directory:

$ cd new_project_name

Install dependencies:

$ npm install

Update Config

Update Application Config at location /config/config.json to set JWT Key, SMTP Details, etc..,

PropertyData TypeDescription
tokenExpiryNumberJWT Token Expiry in Seconds
jwtKeyStringJWT Token Secret, used while generating token
encryptionKeyStringAES Secret, used while encrypting the data
validTenantsJSONObjects of unique application/tenant ids with config
validTenants.<TENANT_ID>StringArray of unique application/tenant ids
validTenants.<TENANT_ID.tenantName>StringUniuqe name for the application
validTenants.<TENANT_ID.allowedUrls>*ArrayArray of unique application/tenant ids
validTenants.<TENANT_ID>.emailJSONEmail customisation config for forgot reset email
validTenants.<TENANT_ID>.email.headerLinkStringURL for the Header Image in Email
validTenants.<TENANT_ID>.email.headerLogoLink(with https)Public Link for your logo
validTenants.<TENANT_ID>.email.endPointLink(with https)Domain name of your UI with page to rest password, email will be sent as {endpoint}/<reset_token>
validTenants.<TENANT_ID>.emailaddressStringFooter text in email
smtpJSONSMTP Config for Sending Forgot Password Emails
smtp.serviceStringSMTP Service Provider
smtp.usernameStringSMTP User Name
smtp.passwordStringSMTP Password

Click here to see list of all Supported SMTP Services

* Available in next release.

Example config.json

{
    "tokenExpiry": 3600, 
    "jwtKey": "3c360c7d4Ab94cO998978c@11c8Ead408I5ab466c7544609b3e3E306aace7e03",
    "encryptionKey": "832720e0-fa6e-43d6-bddc-60035164b4c2-cd0c7f4f-5af2-4dc0-a789-501254e7e528",
    "validTenants": {
        "0177d67f-3b29-42c6-b0cd-2cc70ffccb41": {
            "tenantName": "My Blog", 
            "allowedUrls": ["https://lexicalgrammar.dev"],
            "email": {
                "headerLink": "https://lexicalgrammar.dev", 
                "headerLogo": "https://lexicalgrammar.dev/logo.svg",
                "endPoint": "http://localhost:4001",
                "address": "Made in ❤ with India" 
             }
        }
    },
    "smtp": {
        "service": "gmail", 
        "username": "hello@lexicalgrammar.dev",
        "password": "S3c3r3tP@ssW0rd"
    }
}

# Values provided in the above JSON is just for representational purpose and not actual values.

After updating config.json, you have to update /config/postgres.json to establish db connection.

DDL Script available at DDL Script, after creating the table in Postgres, you can update the following config.

You can read more about Sequelize syntax.

Example postgres.json

{
    "database": "avouch", 
    "userName": "avouch@postgres", 
    "password": "avouch", 
    "host": "avouch.lexicalgrammmar.dev", 
    "port": 5432, 
    "options": {
        "dialect": "postgres",
        "define": {
            "timestamps": false
        },
        "pool": {
            "max": 10,
            "min": 0,
            "acquire": 30000,
            "idle": 10000
        },
        "dialectOptions": {
            "multipleStatements": true,
            "dateStrings": true,
            "useUTC": false,
            "typeCast": true
        },
        "timezone": "+05:30",
        "ssl": true
    }
}

# Values provided in the above JSON is just for representational purpose and not actual values.

After updating the config, you can start Express.js app at http://localhost:4001/ using the following command.

$ node index.js

Command Line Options

This generator can also be further configured with the following command line flags.

    --version        output the version number
-f, --force          force on non-empty directory
-h, --help           output usage information

Available API's

EndpointMethodUsecaseSupported Fields
/registerPOSTCreate new Userregister
/loginPOSTLogin and Get Tokenlogin
/forgotPOSTSend Reset Password Linkforgot
/verify/:{reset_token}GETVerify Reset Tokenreset_token - Token from email link
/resetPOSTUpdate Passwordreset
/registerPUTUpdate Existing User(except email address)register
/authenticatePOSTVerify Token or Get User Infoauthenticate
/refreshPOSTGet new Token using current JWT Tokenrefresh

register

FieldRequiredTypeDescriptionEncoding
firstNameYesStringFirst Name-
lastNameYesStringLast Name-
emailYesStringEmail Address-
passwordYesStringPasswordBase64
authorisedTenantsYesArray with StringsArray of Tenants IDs which user has access to-
tenantIDYesStringCurrent Tenant ID-
accountDetailsYesJSONAdditional user profile fields-
{
    "firstName": "Arunkumar",
    "lastName": "palaniappan",
    "email": "hello@lexicalgrammar.dev",
    "password": "cGFzc3dvcmQ=",
    "authorisedTenants": [
        "0177d67f-3b29-42c6-b0cd-2cc70ffccb41"
    ],
    "accountDetails": {
        "phone": "0000000000",
        "designation": "Full Stack Developer",
        "roleID": "101",
        "userType": "admin"
    },
    "tenantID": "0177d67f-3b29-42c6-b0cd-2cc70ffccb41"
}

Response

Response CodeType or Description
200Success Response with No Content
401User Doesn't have access to particular Tenant
500Internal Server Error

login

FieldRequiredTypeDescriptionEncoding
emailYesStringEmail Address-
passwordYesStringPasswordBase64
tenantIDYesStringCurrent Tenant ID-
{
  "loginID": "hello@lexicalgrammar.dev",
  "password": "cGFzc3dvcmQ=",
  "tenantID": "0177d67f-3b29-42c6-b0cd-2cc70ffccb41"
}

Response

Response CodeType or Description
200Success as json with token
401User Doesn't have access to particular Tenant
500Internal Server Error

forgot

FieldRequiredTypeDescriptionEncoding
emailYesStringEmail Address-
tenantIDYesStringCurrent Tenant ID-
{
  "loginID": "hello@lexicalgrammar.dev",
  "tenantID": "0177d67f-3b29-42c6-b0cd-2cc70ffccb41"
}

Response

Response CodeType or Description
200Success message regarding email sent status
401User Doesn't have access to particular Tenant
500Internal Server Error

reset

FieldRequiredTypeDescriptionEncoding
passwordYesStringNew Passwordbase64
tokenYesStringReset Token-
tenantIDYesStringCurrent Tenant ID-
{
	"password": "MTIzNDU=",
	"tenantID": "0177d67f-3b29-42c6-b0cd-2cc70ffccb41",
	"token": "529438c7ed0cc7c3edb237c5afbe4ab9f31944b0938dc874855e317261943189"
}

Response

Response CodeType or Description
200Success message with password update status
401User Doesn't have access to particular Tenant
500Internal Server Error

authenticate

FieldRequiredTypeDescriptionEncoding
tokenYesStringJWT Token from Login-
tenantIDYesStringCurrent Tenant ID-
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhcnVua3VtYXIucGFsYW5pYXBwYW5AdGhlZGF0YXRlYW0uaW4iLCJyb2xlcyI6WyJhZG1pbiJdLCJhdWQiOiIwMTc3ZDY3Zi0zYjI5LTQyYzYtYjBjZC0yY2M3MGZmY2NiNDEiLCJpc3MiOiJhdm91Y2gtdjAuMC4xLXRlbmFudC0wMTc3ZDY3Zi0zYjI5LTQyYzYtYjBjZC0yY2M3MGZmY2NiNDEiLCJleHAiOjE1ODg2NzEzNjcsImlhdCI6MTU4ODA2NjU2N30.Eu_hXHtzv1RkyZBV832M26uJki_Dbcgt0BrdHg3k9pY",
  "tenantID": "0177d67f-3b29-42c6-b0cd-2cc70ffccb41"
}

Response

Response CodeType or Description
200Success with user profile with all fields from register customer except password and an additional property named validToken as true if the token is valid
401User Doesn't have access to particular Tenant or Token Expired
500Internal Server Error

refresh

FieldRequiredTypeDescriptionEncoding
tokenYesStringJWT Token from Login-
tenantIDYesStringCurrent Tenant ID-
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhcnVua3VtYXIucGFsYW5pYXBwYW5AdGhlZGF0YXRlYW0uaW4iLCJyb2xlcyI6WyJhZG1pbiJdLCJhdWQiOiIwMTc3ZDY3Zi0zYjI5LTQyYzYtYjBjZC0yY2M3MGZmY2NiNDEiLCJpc3MiOiJhdm91Y2gtdjAuMC4xLXRlbmFudC0wMTc3ZDY3Zi0zYjI5LTQyYzYtYjBjZC0yY2M3MGZmY2NiNDEiLCJleHAiOjE1ODg2NzEzNjcsImlhdCI6MTU4ODA2NjU2N30.Eu_hXHtzv1RkyZBV832M26uJki_Dbcgt0BrdHg3k9pY",
  "tenantID": "0177d67f-3b29-42c6-b0cd-2cc70ffccb41"
}

Response

Response CodeType or Description
200Success as json with token
401User Doesn't have access to particular Tenant or Token Expired
500Internal Server Error

Postman collection.json is available at postman/collection.json

Supported SMTP Services

Service
126
163
1und1
AOL
DebugMail
DynectEmail
FastMail
GandiMail
Gmail
Godaddy
GodaddyAsia
GodaddyEurope
hot.ee
Hotmail
iCloud
mail.ee
Mail.ru
Maildev
Mailgun
Mailjet
Mailosaur
Mandrill
Naver
OpenMailBox
Outlook365
Postmark
QQ
QQex
SendCloud
SendGrid
SendinBlue
SendPulse
SES
SES-US-EAST-1
SES-US-WEST-2
SES-EU-WEST-1
Sparkpost
Yahoo
Yandex
Zoho
qiye.aliyun

Contribution

Contributions to avouch are welcome.

Here is how you can contribute to avouch:

Submit bugs and verify existing issues.

Submit pull requests for bug fixes and features and discuss existing proposals.

License

MIT