This repository contains a Node.js RESTful api service for facial recognition authentication. The service employs Microsoft's Cognitive Services for Facial Recognition and Detection.
This web service uses Babel to employ modern JavaScript syntax across the codebase.
Download and install the following prerequisties in order to get started.
Follow the following set of simple instructions in order to get up and running quickly in a development environment.
- Globally install bunyan for logging
npm install -g bunyan
- Install dependencies
npm install
- Start MongoDB
- If you are on OSX and use Homebrew you can simply use Brew Services by default:
brew services start mongodb
- If you are on Windows you can quite simply follow the instructions here and run:
mongod
- Start the server in development mode
npm run watch
The service exposes two endpoints for Facial Authentication - registration and login.
/accounts/register
/accounts/login
Both of these endpoints take a JSON Object body as part of the Request containing two fields:
- Username: String
- Image Data Url: String - Base64 Encoded Image Data Url - See Here!
{
username: 'YourAwesomeUsername',
imageUrl: 'data:image/jpeg;base64,/9j/4AAQSkZ...FjWa0aP/Z'
}
The service is used in conjuction with a Front End mobile application developed using Ionic Native and targets android mobile devices. The API offers a number of routes for updating user scores for a simple mobile game based around mathematical arithmitic.
The routes service a HTTP PUT Request and are defined as follows:
/scores/addition
/scores/subtraction
/scores/multiplication
Each of the endpoints listed above take a JSON Object body as part of the Request containing two fields:
- Username: String
- Score: Number
{
username: 'YourAwesomeUsername',
score: 100
}
The web service has been deployed to Heroku using the Heroku CLI in conjunction with the MongoLab's mLab add-on for cloud hosted databases.
The service is currently available at: https://restify-face-service.herokuapp.com/
Deploy your own Heroku Service using these simple Heroku CLI commands where $MY_APP is your own application name.
heroku create $MY_APP
heroku addons:create mongolab
git add .
git commit -m 'Pushing to Heroku'
git push heroku master
Your brand new Node.js web service is availabe at - https://$MY_APP.herokuapp.com.
Verify that the Node.js web service is alive by using the healthcheck
endpoint with a HTTP client such as cURL or Postman. A healthy application build and deployment should yield a HTTP 200 OK.
For Example:
curl -v https://$MY_APP.herokuapp.com/healthcheck
https://www.youtube.com/watch?v=9fjCsax9fjQ
NOTE: When you create a mLab add-on, the database connection URI is stored as a config var. Heroku config variables are equivalent to an environment variable, which you can use in development and your local environment. You can access this variable in your Node.js code as process.env.MONGODB_URI
.
An API Key for consuming the Microsoft Cognitive Services Face API can be obtained here!.
NOTE: This service currently employs a limited 30 day trial of the Face API service and is scheduled to expire on May 6th 2018.