With Node Knockout 2013 over now, we wanted to thank all participants that used Auth0. We hope we helped simplify the login process in your apps.

Auth0 takes authentication out of your way. Auth0 allows you to connect with +10 identity providers: Amazon, Google, Facebook, Twitter, LiveID, GitHub, 37Signals, PayPal, LinkedIn, Yandex, Fitbit. It also provides a ready to use username/password store (including signup and forgot password flow). It all works out of the box with just a few lines of code.

Auth0 Login Widget

Quick Start in 3 easy steps:

1. Create a free account in Auth0

2. Add code to your app

Add the following code to your HTML and node app:

BROWSER
SERVER
<button onclick="auth0.show()">Login</button>

<script src="https://d19p4zemcycm7a.cloudfront.net/w2/auth0-widget-1.2.1.min.js"></script>

<script type="text/javascript">
var auth0 = new Auth0Widget({
  domain:       'YOUR_DOMAIN.auth0.com',
  clientID:     'YOUR_CLIENT_ID',
  callbackURL:  'http://localhost:3000/',
  callbackOnLocationHash: true
});

// parse the response and store the token in a cookie (or local storage)
auth0.parseHash(window.location.hash, function (profile, id_token) {
  $.cookie('profile', profile);
  $.cookie('id_token', id_token);
});
<script>


var jwt = require('express-jwt');

var authenticate = jwt({
  secret: new Buffer('YOUR_CLIENT_SECRET', 'base64')
  audience: 'YOUR_CLIENT_ID'
});

app.configure(function() {
  ...
  // intercept all /api calls and validate the token
  app.use('/api', authenticate);
});

app.post('/api/foo', 
  function(req, res) {
    // req.user will have all the user attributes
    res.send(200);
  });


3. Call your APIs

Once the user is logged in, you can call your APIs sending the token in the Authorization header.

$.ajaxSetup({
  'beforeSend': function(xhr) {
    if ($.cookie('id_token')) {        
      xhr.setRequestHeader('Authorization', 
            'Bearer ' + $.cookie('id_token'));
    }
  }
});

You are done!


Want to use passport.js? We also support passport.js for server side auhtentication. Here is a tutorial docs.auth0.com/nodejs-tutorial.

Don’t want to use the Login Widget? The widget is customizable but if you want to have your own login UI, you can use Auth0’s API instead: github.com/auth0/auth0.js.

By using Auth0 you don’t have to worry about about user management, single sign on, flow user attributes across layers of your app, integrate with social providers and enterprises and see who is using your app.

We are available on our chat room http://chat.auth0.com and Twitter (@authzero) to help you out if you have any issue.

Happy Noding!

Blog comments powered by Disqus