Last updated 6 years ago by dguttman .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install handshakejs-browser 
SYNC missed versions from official npm registry.



Register app_name

First, register your app_name.

Add script tag

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

<script src='/path/to/handshake.js' 

(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.

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

Setup your /login/success route

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

Node.js Example
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;

See full example nodejs app.

Ruby Example
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"

See full example ruby app.

Video Demo

Dev Setup

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

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

Current Tags

  • 0.0.2                                ...           latest (6 years ago)

2 Versions

  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
Dependents (0)

Copyright 2014 - 2016 © taobao.org |