Permalink
Browse files

Merge pull request #2 from Tobbe/master

Updated to latest node-openid version (0.3.1)
  • Loading branch information...
2 parents 61fe244 + 0863646 commit 86026a72a527c702f9aa42c14440f256d2addafc @alfredwesterveld committed Oct 23, 2011
Showing with 41 additions and 30 deletions.
  1. +6 −2 examples/index.js
  2. +17 −8 lib/google-openid.js
  3. +18 −20 package.json
View
@@ -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
@@ -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
@@ -1,21 +1,19 @@
-{ name: 'google-openid',
- description: 'Authenticate for Google OpenID',
- maintainers: [{
- 'name': 'Alfred Westerveld',
- 'email': 'alfredwesterveld@gmail.com'}],
- "dependencies": {
- "express" : ">= 0.0.1",
- "openid" : ">= 0.1.1 <= 0.1.1"
- },
- version: '0.1.8',
- repository: {
- 'type': 'git',
- 'url': 'https://alfredwesterveld@github.com/alfredwesterveld/node-googleopenid.git' },
- bugs: 'https://github.com/alfredwesterveld/node-googleopenid/issues',
- 'directories' : {
- 'lib' : './lib' },
- 'main' : './lib/google-openid.js',
- "engines" : {
- "node" : ">= 0.2.6 < 0.3.0",
- }
+{ "name": "google-openid",
+ "description": "Authenticate for Google OpenID",
+ "maintainers": [{
+ "name": "Alfred Westerveld",
+ "email": "alfredwesterveld@gmail.com"}],
+ "dependencies": {
+ "express" : ">= 0.0.1",
+ "openid" : "0.3.1"},
+ "version": "0.1.9",
+ "repository": {
+ "type": "git",
+ "url": "https://alfredwesterveld@github.com/alfredwesterveld/node-googleopenid.git" },
+ "bugs": "https://github.com/alfredwesterveld/node-googleopenid/issues",
+ "directories": {
+ "lib": "./lib"},
+ "main": "./lib/google-openid.js",
+ "engines": {
+ "node": ">= 0.4.1 < 0.5.0"}
}

0 comments on commit 86026a7

Please sign in to comment.