Browse files

Updated to latest version of node-openid (0.3.1)

  • Loading branch information...
1 parent 61fe244 commit 69bbe8b9969609d03cb63897b4d6eb5f290442ec @Tobbe Tobbe committed Oct 21, 2011
Showing with 25 additions and 12 deletions.
  1. +6 −2 examples/index.js
  2. +17 −8 lib/google-openid.js
  3. +2 −2 package.json
View
8 examples/index.js
@@ -8,9 +8,13 @@ var app = module.exports = express.createServer();
* Called when Google's OpenID authentication has completed.
* You need to modify this to your needs.
*/
-var onAuthentication = function(req, res, openid_result) {
+var onAuthentication = function(error, req, res, openid_result) {
console.log(openid_result);
- res.send("" + openid_result.identifier);
+ if (error) {
+ res.send(error);
+ } else {
+ res.send("" + openid_result.claimedIdentifier);
+ }
};
var baseURL = 'http://localhost:8888'; // base URL to map to your host
View
25 lib/google-openid.js
@@ -11,25 +11,34 @@ var GoogleOpenid = function(app, baseURL, onAuthentication) {
});
app.get('/googleopenid/authenticate', function(req, res) {
- that.authenticate(req, res);
+ that.authenticate(req, res, onAuthentication);
});
};
GoogleOpenid.prototype.verify = function(req, res, onAuthentication) {
- var openid_result = openid.verifyAssertion(req);
- onAuthentication(req, res, openid_result);
+ this.relyingParty.verifyAssertion(req, function(error, result) {
+ onAuthentication(error, req, res, result);
+ });
};
GoogleOpenid.prototype.authenticate = function(req, res) {
- openid.authenticate(
- GOOGLE_ENDPOINT,
+ this.relyingParty = new openid.RelyingParty(
this.baseURL + "/googleopenid/verify", // our callback URL
null, // realm (optional)
- false, // attempt immediate authentication first?
- function(authUrl) {
+ false, // stateless
+ false, // strict mode
+ null); // List of extensions to enable and include
+
+ this.relyingParty.authenticate(GOOGLE_ENDPOINT, false, function(error, authUrl) {
+ if (error) {
+ onAuthentication(error);
+ } else if (!authUrl) {
+ onAuthentication('Authentication failed - no redirect url received');
+ } else {
res.writeHead(302, { Location: authUrl });
res.end();
- });
+ }
+ });
};
module.exports.create = function(app, baseURL, onAuthentication) {
View
4 package.json
@@ -5,7 +5,7 @@
'email': 'alfredwesterveld@gmail.com'}],
"dependencies": {
"express" : ">= 0.0.1",
- "openid" : ">= 0.1.1 <= 0.1.1"
+ "openid" : "0.3.1"
},
version: '0.1.8',
repository: {
@@ -16,6 +16,6 @@
'lib' : './lib' },
'main' : './lib/google-openid.js',
"engines" : {
- "node" : ">= 0.2.6 < 0.3.0",
+ "node" : ">= 0.4.1 < 0.5.0",
}
}

0 comments on commit 69bbe8b

Please sign in to comment.