Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
Revert "Merge pull request #19 from TDAF/feat/userStandardOpenIdUserI…
Browse files Browse the repository at this point in the history
…nfo"

This reverts commit 95acef4, reversing
changes made to 9d54992.
  • Loading branch information
dll committed May 16, 2017
1 parent 3ce83bc commit 3d69dda
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
24 changes: 14 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ function TAccountsStrategy(options, verify) {
options = options || {};

options.scope = options.scope || [
'openid',
'profile',
'phone',
'email'
'accounts.user.read',
'accounts.user.read.emails',
'accounts.user.read.phones',
'accounts.user.read.services',
'accounts.user.read.profile'
];

options.customHeaders = {
Expand All @@ -71,7 +72,7 @@ function TAccountsStrategy(options, verify) {

options.authorizationURL = options.authorizationURL || 'https://accounts.telefonica.com/telefonica/oauth/authorize';
options.tokenURL = options.tokenURL || 'https://accounts.telefonica.com/telefonica/oauth/token';
options.profileURL = options.profileURL || 'https://accounts.telefonica.com/telefonica/openid/userinfo';
options.profileURL = options.profileURL || 'https://accounts.telefonica.com/api/v1/telefonica/users/me';
options.logoutURL = options.logoutURL || 'https://accounts.telefonica.com/telefonica/logout';

OAuth2Strategy.call(this, options, verify);
Expand Down Expand Up @@ -121,13 +122,16 @@ function TAccountsStrategy(options, verify) {
// see normalized profile http://passportjs.org/docs/profile
var normalizedProfile = {
provider: 'taccounts',
id: body.sub,
displayName: body.name
id: body.userId,
displayName: body.profile.fullname
};

// XXX It should use "type" instead of "primary" (see http://passportjs.org/docs/profile)
// That would break backwards compatibility. We should change it, following semver.
normalizedProfile.emails = [{value: body.email, primary: true}];
normalizedProfile.emails = body.identities.emails.map(function(email) {
return {
value: email.address,
primary: email.main
};
});

// original payload for those who need additional fields from Telefonica Accounts
normalizedProfile.payload = body;
Expand Down
40 changes: 25 additions & 15 deletions test/unit/taccounts-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,28 @@ var events = require('events'),
TAccountsStrategy = require('../../lib');

var TACCOUNTS_PROFILE = {
"email": "frodo.bolson@telefonica.com",
"local_company_alias": "HI_frodo",
"company": "Telefónica S.A.",
"tags": [
"ldap_auth",
"telefonica_user"
],
"sub": "9d2ccf1f-746d-4455-9793-44e1bc8caaa6",
"locale": "es",
"email_verified": true,
"updated_at": "2016-10-25T10:28:35.289Z",
"name": "FRODO BOLSON"
"profile": {
"language_pages": true,
"fullname": " Andrés Iniesta",
"language_code": "es"
},
"lastUpdateTime": "2015-11-09T19:27:36.100Z",
"userId": "e2a1e7c5-9a9b-40b4-b24d-1a7925ba7b92",
"creationTime": "2015-09-18T09:06:53.724Z",
"accountStatus": 1,
"hasPassword": true,
"identities": {
"emails": [
{
"verified": true,
"verificationTime": "2015-09-18T09:08:14.324Z",
"url": "https://accounts.tid.es/telefonica/validate/email",
"creationTime": "2015-09-18T09:06:53.724Z",
"address": "andres@iniesta.com",
"main": true
}
]
}
};

describe('TAccounts basic tests', function() {
Expand Down Expand Up @@ -78,9 +88,9 @@ describe('TAccounts user profile', function() {

strategy.userProfile('faketoken', function(err, profile) {
expect(err).to.not.exist;
expect(profile.displayName).to.be.deep.equal(fakeProfile.name);
expect(profile.id).to.be.deep.equal(fakeProfile.sub);
expect(profile.emails[0]).to.be.deep.equal(fakeProfile.email);
expect(profile.displayName).to.be.deep.equal(fakeProfile.profile.fullname);
expect(profile.id).to.be.deep.equal(fakeProfile.userId);
expect(profile.emails[0].value).to.be.deep.equal(fakeProfile.identities.emails[0].address);
expect(profile.payload).to.be.deep.equal(fakeProfile);
done();
});
Expand Down

0 comments on commit 3d69dda

Please sign in to comment.