Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to set custom fetch attributes as an option on the OpenID strategy #22

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions lib/passport-openid/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,22 @@ function Strategy(options, verify) {
});
extensions.push(sreg);
}

var attributes = {};
if (options.profile) {
var ax = new openid.AttributeExchange({
"http://axschema.org/namePerson" : "required",
"http://axschema.org/namePerson/first": "required",
"http://axschema.org/namePerson/last": "required",
"http://axschema.org/contact/email": "required"
attributes = {
"http://openid.net/schema/namePerson/first": "required",
"http://openid.net/schema/namePerson/last": "required",
"http://openid.net/schema/contact/internet/email": "required"
};
}
if (options.extensions) {
Object.keys(options.extensions).forEach(function (ext) {
attributes[ext] = options.extensions[ext];
});
}
if (Object.keys(attributes).length > 0) {
var ax = new openid.AttributeExchange(attributes);
extensions.push(ax);
}

Expand All @@ -116,7 +125,7 @@ function Strategy(options, verify) {
var papeOptions = {};
if (options.pape.hasOwnProperty("maxAuthAge")) {
papeOptions.max_auth_age = options.pape.maxAuthAge;
}
}
if (options.pape.preferredAuthPolicies) {
if (typeof options.pape.preferredAuthPolicies === "string") {
papeOptions.preferred_auth_policies = options.pape.preferredAuthPolicies;
Expand Down Expand Up @@ -440,21 +449,21 @@ Strategy.prototype.loadDiscoveredInformation = function(fn) {
Strategy.prototype._parseProfileExt = function(params) {
var profile = {};

// parse simple registration parameters
profile.displayName = params['fullname'];
profile.emails = [{ value: params['email'] }];

// TODO: The hard-coded alias stuff really needs to go.
var email = params['email'] || params['alias1'];
var first = params['first'] || params['alias2'];
var last = params['last'] || params['alias3'];

profile.emails = [{ value: email }];
// parse attribute exchange parameters
profile.name = { familyName: params['lastname'],
givenName: params['firstname'] };
profile.name = { familyName: last,
givenName: first };
if (!profile.displayName) {
if (params['firstname'] && params['lastname']) {
profile.displayName = params['firstname'] + ' ' + params['lastname'];
if (first && last) {
profile.displayName = first + ' ' + last;
}
}
if (!profile.emails) {
profile.emails = [{ value: params['email'] }];
}

return profile;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "passport-openid",
"version": "0.3.1",
"version": "0.3.4",
"description": "OpenID authentication strategy for Passport.",
"keywords": ["passport", "openid", "auth", "authn", "authentication", "identity"],
"repository": {
Expand Down