Skip to content

Commit

Permalink
Implement profile parsing and verify callback.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Feb 17, 2013
1 parent ef2df73 commit 7b18c36
Showing 1 changed file with 60 additions and 25 deletions.
85 changes: 60 additions & 25 deletions lib/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ Strategy.prototype.authenticate = function(req, options) {
console.log('LOAD: ' + load);

if (load) {

var parsed = url.parse(self._userInfoURL, true);
parsed.query['schema'] = 'openid';
delete parsed.search;
Expand All @@ -142,37 +141,73 @@ Strategy.prototype.authenticate = function(req, options) {
console.log('PROFILE');
console.log(body);
console.log('-------');

var profile = {};

try {
var json = JSON.parse(body);

profile.id = json.sub;
// Prior to OpenID Connect Basic Client Profile 1.0 - draft 22, the
// "sub" key was named "user_id". Many providers still use the old
// key, so fallback to that.
if (!profile.id) {
profile.id = json.user_id;
}

profile.displayName = json.name;
profile.name = { familyName: json.family_name,
givenName: json.given_name,
middleName: json.middle_name };

profile._raw = body;
profile._json = json;

onProfileLoaded(profile);
} catch(e) {
return self.error(ex);
}
});
}
});

/*
self._loadUserProfile(accessToken, function(err, profile) {
if (err) { return self.error(err); };
function verified(err, user, info) {
if (err) { return self.error(err); }
if (!user) { return self.fail(info); }
self.success(user, info);
} else {
onProfileLoaded();
}

if (self._passReqToCallback) {
var arity = self._verify.length;
if (arity == 6) {
self._verify(req, accessToken, refreshToken, params, profile, verified);
} else { // arity == 5
self._verify(req, accessToken, refreshToken, profile, verified);
function onProfileLoaded(profile) {
function verified(err, user, info) {
if (err) { return self.error(err); }
if (!user) { return self.fail(info); }
self.success(user, info);
}
} else {
var arity = self._verify.length;
if (arity == 5) {
self._verify(accessToken, refreshToken, params, profile, verified);
} else { // arity == 4
self._verify(accessToken, refreshToken, profile, verified);

if (self._passReqToCallback) {
var arity = self._verify.length;
if (arity == 9) {
self._verify(req, iss, sub, profile, jwtClaims, accessToken, refreshToken, params, verified);
} else if (arity == 8) {
self._verify(req, iss, sub, profile, accessToken, refreshToken, params, verified);
} else if (arity == 7) {
self._verify(req, iss, sub, profile, accessToken, refreshToken, verified);
} else if (arity == 5) {
self._verify(req, iss, sub, profile, verified);
} else { // arity == 4
self._verify(req, iss, sub, verified);
}
} else {
var arity = self._verify.length;
if (arity == 8) {
self._verify(iss, sub, profile, jwtClaims, accessToken, refreshToken, params, verified);
} else if (arity == 7) {
self._verify(iss, sub, profile, accessToken, refreshToken, params, verified);
} else if (arity == 6) {
self._verify(iss, sub, profile, accessToken, refreshToken, verified);
} else if (arity == 4) {
self._verify(iss, sub, profile, verified);
} else { // arity == 3
self._verify(iss, sub, verified);
}
}
}
});
*/
});
} else {
var params = this.authorizationParams(options);
Expand Down

0 comments on commit 7b18c36

Please sign in to comment.