Node
Getting started
You can manually add it to your package.json or install and save it with the following command:
npm install tcell-hooks --save
There are three options for calling the hooks from your application code:
By providing an Express request object and having the tCell Agent extract the relevant details from it:
1var TCellHooks = require('tcell-hooks').v1;23// successful login4var username = 'some-user-id',5sessionId = req.sessionID6TCellHooks.sendExpressLoginEventSuccess(req, username, sessionId);78// failed login9var username = 'some-user-id',10sessionId = req.sessionID,11userValid = false12TCellHooks.sendExpressLoginEventFailure(req, username, sessionId, userValid);By providing a Hapi request object and having the TCell Agent extract the relevant details from it:
1var TCellHooks = require('tcell-hooks').v1;23// successful login4var username = 'some-user-id',5sessionId = 'session-id'6TCellHooks.sendHapiLoginEventSuccess(req, username, sessionId);78// failed login9var username = 'some-user-id',10sessionId = 'session-id'11userValid = false12TCellHooks.sendHapiLoginEventFailure(req, username, sessionId, userValid);By providing each individual piece of information required for the tCell event:
1var TCellHooks = require('tcell-hooks').v1;23// successful login4// NOTE: this is how you would obtain this info from an ExpressJS request.5// Obtaining this info in a different framework will likely differ6var username = 'some-user-id',7sessionId = req.sessionID,8userAgent = req.get('User-Agent'),9referrer = req.get('Referrer'),10remoteAddress = req.headers['x-forwarded-for'] || req.connection.remoteAddress,11headerKeys = Object.keys(req.headers),12documentUri = req.protocol + '://' + req.get('Host') + req.originalUrl13TCellHooks.sendLoginEventSuccess(14username,15sessionId,16userAgent,17referrer,18remoteAddress,19headerKeys,20documentUri);2122// failed login23// NOTE: this is how you would obtain this info from an ExpressJS request.24// Obtaining this info in a different framework will likely differ25var username = 'some-user-id',26sessionId = req.sessionID,27userAgent = req.get('User-Agent'),28referrer = req.get('Referrer'),29remoteAddress = req.headers['x-forwarded-for'] || req.connection.remoteAddress,30headerKeys = Object.keys(req.headers),31documentUri = req.protocol + '://' + req.get('Host') + req.originalUrl,32userValid = false33TCellHooks.sendLoginEventFailure(34username,35sessionId,36userAgent,37referrer,38remoteAddress,39headerKeys,40documentUri41userValid);
API
1function sendLoginEventSuccess (2userId,3sessionId,4userAgent,5referrer,6remoteAddress,7headerKeys,8documentUri) {9}
- userId (string) : Identification used for the user (i.e. email, username)
- sessionId (string) : (Optional) Session ID for user logging in. This will be HMAC'ed by the Agent before being sent
- userAgent (string) : Optional) User agent taken from header
- referrer (string) : (Optional) Referrer taken from header
- remoteAddress (string) : (Optional) IP of the Request
- headerKeys (string) : (Optional) An array of the header keys. The order is important (do not sort the array)
- documentUri (string) : (Optional) Document URI taken from request
1function sendLoginEventFailure (2userId,3sessionId,4userAgent,5referrer,6remoteAddress,7headerKeys,8documentUri,9userValid) {10}
- userId (string) : Identification used for the user (i.e. email, username)
- sessionId (string) : (Optional) Session ID for user logging in. This will be HMAC'ed by the Agent before being sent
- userAgent (string) : (Optional) User agent taken from header
- referrer (string) : (Optional) Referrer taken from header
- remoteAddress (string) : (Optional) IP of the Request
- headerKeys (string) : (Optional) An array of the header keys. The order is important (do not sort the array)
- documentUri (string) : (Optional) Document URI taken from request
- userValid (boolean) : (Optional) Set as true if exists, other false. Defaults to null.
1function sendExpressLoginEventSuccess (2request,3userId,4sessionId) {5}
- request (object) : Request object provided by ExpressJS
- userId (string) : Identification used for the user (i.e. email, username)
- sessionId (string) : (Optional) Session ID for user logging in. This will be HMAC'ed by the Agent before being sent
1function sendExpressLoginEventFailure (2request,3userId,4sessionId,5userValid) {6}
- request (object) : Request object provided by ExpressJS
- userId (string) : Identification used for the user (i.e. email, username)
- sessionId (string) : (Optional) Session ID for user logging in. This will be HMAC'ed by the Agent before being sent
- userValid (boolean) : (Optional) Set as true if exists, other false. Defaults to null.
1function sendHapiLoginEventSuccess (2request,3userId,4sessionId) {5}
- request (object) : Request object provided by Hapi
- userId (string) : Identification used for the user (i.e. email, username)
- sessionId (string) : (Optional) Session ID for user logging in. This will be HMAC'ed by the Agent before being sent
1function sendHapiLoginEventFailure (2request,3userId,4sessionId,5userValid) {6}
- request (object) : Request object provided by Hapi
- userId (string) : Identification used for the user (i.e. email, username)
- sessionId (string) : (Optional) Session ID for user logging in. This will be HMAC'ed by the Agent before being sent
- userValid (boolean) : (Optional) Set as true if exists, other false. Defaults to null.
Password Hash
When you send a secured hashed password to the tCell cloud, you create a more robust Account Takeover response. See Password Hash for more information.
Important
If the tcell_agent is not installed or if it's disabled, this code will do nothing and should have no performance effect on your app.