# NodeJS
This module is used for authentication between clients and equeum.com server, currently we are using Okta as the users managements.
Sample usage:
var app = require('express')();
var server = require('http').Server(app);
var MachiAuth = require('machi-auth').MachiAuth;
var machiAuth = new MachiAuth();
machiAuth.init(app, {
baseURL: '< The website base url >',
// apiKey: '< The okta api key >',
membershipDB:'< The postgres membership database connection, see https://github.com/membership/membership.db/tree/master/postgres>',
sendgridApiKey: "< The api key for send grid API >",
cookies: {
secret: 'The cookies secret'
}
});
machiAuth.defineRoutes();
app.get('/secret page',machiAuth.middleware.loginRequired,function(req,res){
res.json(req.user);
});
Options- You can customize the following options
Define the routes:
options.routes = {
login: '/login',
logout: '/logout',
register: '/register',
activateUser: '/activateUser',
forgotPassword: '/forgotPassword',
resetPassword: '/resetPassword',
unauthorized: '/unauthorized'
}
Define the email options
options.emails={
emailTemplateFolder:'< Set to a new folder to change the default one >',
templates:{
verify: {
title: 'Confirm your account',
view: 'verify-email.html'
},
welcome: {
title: 'Thanks for signing up',
view: 'welcome-email.html'
},
resetPassword: {
title: 'Reset your Password',
view: 'reset-password-email.html'
},
passwordChanged: {
title: 'Your password has been changed',
view: 'password-changed-email.html'
},
changeEmail: {
title: 'Change Email',
view: 'change-email.html'
}
},
fromEmail:'no-reply@equeum.com',
fromEmailTitle:'Equeum'
}
AccessTokens usage
Request for new AccessToken:
Request api /tokens/requestToken
Use the AccessToken to consume the protected resources:
Include the accessToken in req.headers or req.cookies and you will be authorized