Skip to content
Oeiuwq Faith Blog OpenSource Porfolio

handshakejs/handshakejs-script

Open source JavaScript API for authenticating your users without requiring a password.

handshakejs/handshakejs-script.json
{
"createdAt": "2013-10-17T18:23:50Z",
"defaultBranch": "master",
"description": "Open source JavaScript API for authenticating your users without requiring a password.",
"fullName": "handshakejs/handshakejs-script",
"homepage": "",
"language": "JavaScript",
"name": "handshakejs-script",
"pushedAt": "2014-06-10T03:39:19Z",
"stargazersCount": 45,
"topics": [],
"updatedAt": "2021-12-23T09:06:17Z",
"url": "https://github.com/handshakejs/handshakejs-script"
}

First, register your app_name.

Next, place the handshake.js script tag where you want the login form displayed.

<script unsrc='/path/to/handshake.js'
data-app_name="your_app_name"
data-root_url="https://handshakejs.herokuapp.com"></script>

(Get the latest handshake.js here. Replace the data-app_name with the one you registered.)

Next, bind to the handshake:login_confirm event to get the successful login data. This is where you would make an internal request to your application to set the session for the user.

<script>
handshake.script.addEventListener('handshake:login_confirm', function(e) {
console.log(e.data);
$.post("/login/success", {email: e.data.identity.email, hash: e.data.identity.hash}, function(data) {
window.location.href = "/dashboard";
});
}, false);
</script>

Lastly, setup a /login/success route to set your app’s session. There are examples below in different languages.

var handshakejs = require('handshakejs')('YOUR_SALT');
app.post('/login/success', function(req, res) {
handshakejs.validate({email: req.body.email, hash: req.body.hash}, function(err, result) {
if (!err) {
req.session.user = req.body.email;
}
res.redirect('/dashboard');
});
});

See full example nodejs app.

post "/login/success" do
Handshakejs.salt = ENV['SALT']
result = Handshakejs.validate({email: params[:email], hash: params[:hash]})
session[:user] = params[:email] if result
redirect "/dashboard"
end

See full example ruby app.

Dev setup is if you want to work on the library yourself.

$ npm install -g grunt-cli
$ npm install
$ grunt