I am happy to announce the immediate availability of my implementation of OpenID for node.js. I’ve spent a few nights working on this, which is my first node.js library, and I finally got to the point where the library was complete enough for a first public release.
Installation
Installing is very simple using npm:
npm install openid
If you don’t use npm, you can of course just download and require. Remember dependencies from the lib folder, and remember adding paths to require.paths if necessary.
Usage
One of the main design goals for the library has been simplicity. Using OpenID for node.js is pretty simple, here’s a minimal sample server:
var openid = require('openid');
var url = require('url');
var server = require('http').createServer(
function(req, res)
{
var parsedUrl = url.parse(req.url, true);
if(parsedUrl.pathname == '/verify')
{
// Verify identity assertion
var result = openid.verifyAssertion(req); // or req.url
res.writeHead(200);
res.end(result.authenticated ? 'Success
' : 'Failure
');
}
else if(parsedUrl.pathname == '/authenticate')
{
// Resolve identifier, associate, build authentication URL
openid.authenticate(
parsedUrl.query.openid_identifier, // user supplied identifier
'http://example.com/verify', // our callback URL
null, // realm (optional)
false, // attempt immediate authentication first?
function(authUrl)
{
res.writeHead(302, { Location: authUrl });
res.end();
});
}
else
{
// Deliver an OpenID form on all other URLs
res.writeHead(200);
res.end('<!DOCTYPE html><html><body>'
+ '<form method="get" action="/authenticate">'
+ '<p>Login using OpenID</p>'
+ '<input name="openid_identifier" />'
+ '<input type="submit" value="Login" />'
+ '</form></body></html>');
}
});
server.listen(80);
Source
I use GitHub for source control, so you can follow me and the node-openid repository there.
Licensing
OpenID for node.js is licensed under the MIT license. Details can be found in the LICENSE file on GitHub. The library includes third-party code released under the MIT and BSD licenses, see README for details.
Wishes for node.js
I’ve come across a couple of missing features which I’d love to see in node.js in the near future:
- The
cryptomodule should support Diffie-Hellman key exchange (OpenSSL supports it, so please provide bindings) - A big integer library should be available alongside the
cryptomodule, and preferably seamlessly integrated with thecryptomodule – perhaps bindings to the GMP library could suffice? - More seamless unit testing libraries would be good
In addition, I would love to see a tailored IDE for node.js applications.