Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated to latest version of node-openid (0.3.1)

  • Loading branch information...
commit 69bbe8b9969609d03cb63897b4d6eb5f290442ec 1 parent 61fe244
Tobbe Lundberg Tobbe authored

Showing 3 changed files with 25 additions and 12 deletions. Show diff stats Hide diff stats

  1. +6 2 examples/index.js
  2. +17 8 lib/google-openid.js
  3. +2 2 package.json
8 examples/index.js
@@ -8,9 +8,13 @@ var app = module.exports = express.createServer();
8 8 * Called when Google's OpenID authentication has completed.
9 9 * You need to modify this to your needs.
10 10 */
11   -var onAuthentication = function(req, res, openid_result) {
  11 +var onAuthentication = function(error, req, res, openid_result) {
12 12 console.log(openid_result);
13   - res.send("" + openid_result.identifier);
  13 + if (error) {
  14 + res.send(error);
  15 + } else {
  16 + res.send("" + openid_result.claimedIdentifier);
  17 + }
14 18 };
15 19
16 20 var baseURL = 'http://localhost:8888'; // base URL to map to your host
25 lib/google-openid.js
@@ -11,25 +11,34 @@ var GoogleOpenid = function(app, baseURL, onAuthentication) {
11 11 });
12 12
13 13 app.get('/googleopenid/authenticate', function(req, res) {
14   - that.authenticate(req, res);
  14 + that.authenticate(req, res, onAuthentication);
15 15 });
16 16 };
17 17
18 18 GoogleOpenid.prototype.verify = function(req, res, onAuthentication) {
19   - var openid_result = openid.verifyAssertion(req);
20   - onAuthentication(req, res, openid_result);
  19 + this.relyingParty.verifyAssertion(req, function(error, result) {
  20 + onAuthentication(error, req, res, result);
  21 + });
21 22 };
22 23
23 24 GoogleOpenid.prototype.authenticate = function(req, res) {
24   - openid.authenticate(
25   - GOOGLE_ENDPOINT,
  25 + this.relyingParty = new openid.RelyingParty(
26 26 this.baseURL + "/googleopenid/verify", // our callback URL
27 27 null, // realm (optional)
28   - false, // attempt immediate authentication first?
29   - function(authUrl) {
  28 + false, // stateless
  29 + false, // strict mode
  30 + null); // List of extensions to enable and include
  31 +
  32 + this.relyingParty.authenticate(GOOGLE_ENDPOINT, false, function(error, authUrl) {
  33 + if (error) {
  34 + onAuthentication(error);
  35 + } else if (!authUrl) {
  36 + onAuthentication('Authentication failed - no redirect url received');
  37 + } else {
30 38 res.writeHead(302, { Location: authUrl });
31 39 res.end();
32   - });
  40 + }
  41 + });
33 42 };
34 43
35 44 module.exports.create = function(app, baseURL, onAuthentication) {
4 package.json
@@ -5,7 +5,7 @@
5 5 'email': 'alfredwesterveld@gmail.com'}],
6 6 "dependencies": {
7 7 "express" : ">= 0.0.1",
8   - "openid" : ">= 0.1.1 <= 0.1.1"
  8 + "openid" : "0.3.1"
9 9 },
10 10 version: '0.1.8',
11 11 repository: {
@@ -16,6 +16,6 @@
16 16 'lib' : './lib' },
17 17 'main' : './lib/google-openid.js',
18 18 "engines" : {
19   - "node" : ">= 0.2.6 < 0.3.0",
  19 + "node" : ">= 0.4.1 < 0.5.0",
20 20 }
21 21 }

0 comments on commit 69bbe8b

Please sign in to comment.
Something went wrong with that request. Please try again.