diff --git a/Makefile b/Makefile index 0bbe20c..d148666 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ include node_modules/make-node/main.mk SOURCES = lib/*.js lib/**/*.js -TESTS = test/*.test.js +TESTS = test/*.test.js test/**/*.test.js LCOVFILE = ./reports/coverage/lcov.info diff --git a/lib/profile/openid.js b/lib/profile/openid.js index c8b5a4f..2056feb 100644 --- a/lib/profile/openid.js +++ b/lib/profile/openid.js @@ -1,6 +1,18 @@ /** * Parse profile. * + * Parses user profiles as fetched from Google's OpenID Connect-compatible user + * info endpoint. + * + * The amount of detail in the profile varies based on the scopes granted by the + * user. The following scope values add additional data: + * + * `profile` - basic profile information + * `email` - email address + * + * References: + * - https://developers.google.com/identity/protocols/OpenIDConnect + * * @param {object|string} json * @return {object} * @access public diff --git a/package.json b/package.json index 3348c8a..9deb830 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,6 @@ "node": ">= 0.4.0" }, "scripts": { - "test": "node_modules/.bin/mocha --require test/bootstrap/node test/*.test.js" + "test": "node_modules/.bin/mocha --require test/bootstrap/node test/*.test.js test/**/*.test.js" } } diff --git a/test/fixtures/userinfo/userinfo-with-profile.json b/test/fixtures/userinfo/userinfo-with-profile.json new file mode 100644 index 0000000..056d1d4 --- /dev/null +++ b/test/fixtures/userinfo/userinfo-with-profile.json @@ -0,0 +1,8 @@ +{ + "sub": "111111111111111111111", + "name": "Jared Hanson", + "given_name": "Jared", + "family_name": "Hanson", + "picture": "https://lh3.googleusercontent.com/-XxXXxxXxXXX/AAAAAAAAAAI/AAAAAAAAAAA/0000xxxxx0X/photo.jpg", + "locale": "en" +} diff --git a/test/profile/openid.test.js b/test/profile/openid.test.js new file mode 100644 index 0000000..da9fbb0 --- /dev/null +++ b/test/profile/openid.test.js @@ -0,0 +1,29 @@ +var Profile = require('../../lib/profile/openid') + , fs = require('fs') + + +describe('OpenIDProfile.parse', function() { + + describe('profile with profile scope', function() { + var profile; + + before(function(done) { + fs.readFile('test/fixtures/userinfo/userinfo-with-profile.json', 'utf8', function(err, data) { + if (err) { return done(err); } + profile = Profile.parse(data); + done(); + }); + }); + + it('should parse profile', function() { + expect(profile.id).to.equal('111111111111111111111'); + expect(profile.displayName).to.equal('Jared Hanson'); + expect(profile.name.familyName).to.equal('Hanson'); + expect(profile.name.givenName).to.equal('Jared'); + expect(profile.photos).to.have.length(1); + expect(profile.emails).to.be.undefined; + expect(profile.photos[0].value).to.equal('https://lh3.googleusercontent.com/-XxXXxxXxXXX/AAAAAAAAAAI/AAAAAAAAAAA/0000xxxxx0X/photo.jpg'); + }); + }); + +}); \ No newline at end of file