{"action":"created","comment":{"url":"https://api.github.com/repos/agco/passport-openam/pulls/comments/29007406","id":29007406,"diff_hunk":"@@ -78,3 +71,52 @@ module.exports = function createStrategy(redis, options) {\n     });\n \n };\n+\n+function createOauth2Strategy(redis, options) {\n+    return new OAuth2Strategy(function(token, done) {\n+        var hashedToken = MD5(token),\n+            infoURL = options.openAMInfoURL,\n+            user;\n+\n+        return getRedis(redis, hashedToken, options.redisDBIndex)\n+            .spread(getTokenInfo)\n+            .spread(storeUser)\n+            .spread(validate)\n+            .catch(invalidate);\n+\n+        function getTokenInfo(selection, value) {\n+            if (value) return done(null, JSON.parse(value));\n+            return $http.get(infoURL+'?access_token='+token, {json: true});\n+        }\n+\n+        function storeUser(res, body) {\n+            user = body;\n+            if (!body) done(null, body);\n+            redis.multi();\n+            redis.select(options.redisDBIndex);\n+            redis.set(hashedToken, JSON.stringify(body));\n+            return redis.exec();","path":"lib/redisOpenAM.js","position":62,"original_position":62,"commit_id":"1530678e4daf5a634498ce11f0594b967a65cffd","original_commit_id":"1530678e4daf5a634498ce11f0594b967a65cffd","user":{"login":"kristofsajdak","id":666156,"avatar_url":"https://avatars.githubusercontent.com/u/666156?v=3","gravatar_id":"","url":"https://api.github.com/users/kristofsajdak","html_url":"https://github.com/kristofsajdak","followers_url":"https://api.github.com/users/kristofsajdak/followers","following_url":"https://api.github.com/users/kristofsajdak/following{/other_user}","gists_url":"https://api.github.com/users/kristofsajdak/gists{/gist_id}","starred_url":"https://api.github.com/users/kristofsajdak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kristofsajdak/subscriptions","organizations_url":"https://api.github.com/users/kristofsajdak/orgs","repos_url":"https://api.github.com/users/kristofsajdak/repos","events_url":"https://api.github.com/users/kristofsajdak/events{/privacy}","received_events_url":"https://api.github.com/users/kristofsajdak/received_events","type":"User","site_admin":false},"body":"wouldn't it be a bit cleaner to return the user from the function ?\r\n\r\n```javascript\r\nreturn redis.exec().then(function() { return body })\r\n```\r\n\r\nnitpicking perhaps, but I favour a functional approach","created_at":"2015-04-23T21:52:30Z","updated_at":"2015-04-23T21:52:30Z","html_url":"https://github.com/agco/passport-openam/pull/1#discussion_r29007406","pull_request_url":"https://api.github.com/repos/agco/passport-openam/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/agco/passport-openam/pulls/comments/29007406"},"html":{"href":"https://github.com/agco/passport-openam/pull/1#discussion_r29007406"},"pull_request":{"href":"https://api.github.com/repos/agco/passport-openam/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/agco/passport-openam/pulls/1","id":33994200,"html_url":"https://github.com/agco/passport-openam/pull/1","diff_url":"https://github.com/agco/passport-openam/pull/1.diff","patch_url":"https://github.com/agco/passport-openam/pull/1.patch","issue_url":"https://api.github.com/repos/agco/passport-openam/issues/1","number":1,"state":"open","locked":false,"title":"Feature/oauth2","user":{"login":"broguinn","id":5201136,"avatar_url":"https://avatars.githubusercontent.com/u/5201136?v=3","gravatar_id":"","url":"https://api.github.com/users/broguinn","html_url":"https://github.com/broguinn","followers_url":"https://api.github.com/users/broguinn/followers","following_url":"https://api.github.com/users/broguinn/following{/other_user}","gists_url":"https://api.github.com/users/broguinn/gists{/gist_id}","starred_url":"https://api.github.com/users/broguinn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broguinn/subscriptions","organizations_url":"https://api.github.com/users/broguinn/orgs","repos_url":"https://api.github.com/users/broguinn/repos","events_url":"https://api.github.com/users/broguinn/events{/privacy}","received_events_url":"https://api.github.com/users/broguinn/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-04-23T20:39:23Z","updated_at":"2015-04-23T21:52:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9f964c1a32105312636b5e68fdf0440b3fe129c0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/agco/passport-openam/pulls/1/commits","review_comments_url":"https://api.github.com/repos/agco/passport-openam/pulls/1/comments","review_comment_url":"https://api.github.com/repos/agco/passport-openam/pulls/comments{/number}","comments_url":"https://api.github.com/repos/agco/passport-openam/issues/1/comments","statuses_url":"https://api.github.com/repos/agco/passport-openam/statuses/1530678e4daf5a634498ce11f0594b967a65cffd","head":{"label":"agco:feature/oauth2","ref":"feature/oauth2","sha":"1530678e4daf5a634498ce11f0594b967a65cffd","user":{"login":"agco","id":8579835,"avatar_url":"https://avatars.githubusercontent.com/u/8579835?v=3","gravatar_id":"","url":"https://api.github.com/users/agco","html_url":"https://github.com/agco","followers_url":"https://api.github.com/users/agco/followers","following_url":"https://api.github.com/users/agco/following{/other_user}","gists_url":"https://api.github.com/users/agco/gists{/gist_id}","starred_url":"https://api.github.com/users/agco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agco/subscriptions","organizations_url":"https://api.github.com/users/agco/orgs","repos_url":"https://api.github.com/users/agco/repos","events_url":"https://api.github.com/users/agco/events{/privacy}","received_events_url":"https://api.github.com/users/agco/received_events","type":"Organization","site_admin":false},"repo":{"id":33536992,"name":"passport-openam","full_name":"agco/passport-openam","owner":{"login":"agco","id":8579835,"avatar_url":"https://avatars.githubusercontent.com/u/8579835?v=3","gravatar_id":"","url":"https://api.github.com/users/agco","html_url":"https://github.com/agco","followers_url":"https://api.github.com/users/agco/followers","following_url":"https://api.github.com/users/agco/following{/other_user}","gists_url":"https://api.github.com/users/agco/gists{/gist_id}","starred_url":"https://api.github.com/users/agco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agco/subscriptions","organizations_url":"https://api.github.com/users/agco/orgs","repos_url":"https://api.github.com/users/agco/repos","events_url":"https://api.github.com/users/agco/events{/privacy}","received_events_url":"https://api.github.com/users/agco/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/agco/passport-openam","description":"","fork":false,"url":"https://api.github.com/repos/agco/passport-openam","forks_url":"https://api.github.com/repos/agco/passport-openam/forks","keys_url":"https://api.github.com/repos/agco/passport-openam/keys{/key_id}","collaborators_url":"https://api.github.com/repos/agco/passport-openam/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/agco/passport-openam/teams","hooks_url":"https://api.github.com/repos/agco/passport-openam/hooks","issue_events_url":"https://api.github.com/repos/agco/passport-openam/issues/events{/number}","events_url":"https://api.github.com/repos/agco/passport-openam/events","assignees_url":"https://api.github.com/repos/agco/passport-openam/assignees{/user}","branches_url":"https://api.github.com/repos/agco/passport-openam/branches{/branch}","tags_url":"https://api.github.com/repos/agco/passport-openam/tags","blobs_url":"https://api.github.com/repos/agco/passport-openam/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/agco/passport-openam/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/agco/passport-openam/git/refs{/sha}","trees_url":"https://api.github.com/repos/agco/passport-openam/git/trees{/sha}","statuses_url":"https://api.github.com/repos/agco/passport-openam/statuses/{sha}","languages_url":"https://api.github.com/repos/agco/passport-openam/languages","stargazers_url":"https://api.github.com/repos/agco/passport-openam/stargazers","contributors_url":"https://api.github.com/repos/agco/passport-openam/contributors","subscribers_url":"https://api.github.com/repos/agco/passport-openam/subscribers","subscription_url":"https://api.github.com/repos/agco/passport-openam/subscription","commits_url":"https://api.github.com/repos/agco/passport-openam/commits{/sha}","git_commits_url":"https://api.github.com/repos/agco/passport-openam/git/commits{/sha}","comments_url":"https://api.github.com/repos/agco/passport-openam/comments{/number}","issue_comment_url":"https://api.github.com/repos/agco/passport-openam/issues/comments{/number}","contents_url":"https://api.github.com/repos/agco/passport-openam/contents/{+path}","compare_url":"https://api.github.com/repos/agco/passport-openam/compare/{base}...{head}","merges_url":"https://api.github.com/repos/agco/passport-openam/merges","archive_url":"https://api.github.com/repos/agco/passport-openam/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/agco/passport-openam/downloads","issues_url":"https://api.github.com/repos/agco/passport-openam/issues{/number}","pulls_url":"https://api.github.com/repos/agco/passport-openam/pulls{/number}","milestones_url":"https://api.github.com/repos/agco/passport-openam/milestones{/number}","notifications_url":"https://api.github.com/repos/agco/passport-openam/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/agco/passport-openam/labels{/name}","releases_url":"https://api.github.com/repos/agco/passport-openam/releases{/id}","created_at":"2015-04-07T10:33:31Z","updated_at":"2015-04-20T20:05:00Z","pushed_at":"2015-04-23T20:39:24Z","git_url":"git://github.com/agco/passport-openam.git","ssh_url":"git@github.com:agco/passport-openam.git","clone_url":"https://github.com/agco/passport-openam.git","svn_url":"https://github.com/agco/passport-openam","homepage":null,"size":156,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"agco:master","ref":"master","sha":"2d5bd08ca5748106654ade45da79f95e74851109","user":{"login":"agco","id":8579835,"avatar_url":"https://avatars.githubusercontent.com/u/8579835?v=3","gravatar_id":"","url":"https://api.github.com/users/agco","html_url":"https://github.com/agco","followers_url":"https://api.github.com/users/agco/followers","following_url":"https://api.github.com/users/agco/following{/other_user}","gists_url":"https://api.github.com/users/agco/gists{/gist_id}","starred_url":"https://api.github.com/users/agco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agco/subscriptions","organizations_url":"https://api.github.com/users/agco/orgs","repos_url":"https://api.github.com/users/agco/repos","events_url":"https://api.github.com/users/agco/events{/privacy}","received_events_url":"https://api.github.com/users/agco/received_events","type":"Organization","site_admin":false},"repo":{"id":33536992,"name":"passport-openam","full_name":"agco/passport-openam","owner":{"login":"agco","id":8579835,"avatar_url":"https://avatars.githubusercontent.com/u/8579835?v=3","gravatar_id":"","url":"https://api.github.com/users/agco","html_url":"https://github.com/agco","followers_url":"https://api.github.com/users/agco/followers","following_url":"https://api.github.com/users/agco/following{/other_user}","gists_url":"https://api.github.com/users/agco/gists{/gist_id}","starred_url":"https://api.github.com/users/agco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agco/subscriptions","organizations_url":"https://api.github.com/users/agco/orgs","repos_url":"https://api.github.com/users/agco/repos","events_url":"https://api.github.com/users/agco/events{/privacy}","received_events_url":"https://api.github.com/users/agco/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/agco/passport-openam","description":"","fork":false,"url":"https://api.github.com/repos/agco/passport-openam","forks_url":"https://api.github.com/repos/agco/passport-openam/forks","keys_url":"https://api.github.com/repos/agco/passport-openam/keys{/key_id}","collaborators_url":"https://api.github.com/repos/agco/passport-openam/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/agco/passport-openam/teams","hooks_url":"https://api.github.com/repos/agco/passport-openam/hooks","issue_events_url":"https://api.github.com/repos/agco/passport-openam/issues/events{/number}","events_url":"https://api.github.com/repos/agco/passport-openam/events","assignees_url":"https://api.github.com/repos/agco/passport-openam/assignees{/user}","branches_url":"https://api.github.com/repos/agco/passport-openam/branches{/branch}","tags_url":"https://api.github.com/repos/agco/passport-openam/tags","blobs_url":"https://api.github.com/repos/agco/passport-openam/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/agco/passport-openam/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/agco/passport-openam/git/refs{/sha}","trees_url":"https://api.github.com/repos/agco/passport-openam/git/trees{/sha}","statuses_url":"https://api.github.com/repos/agco/passport-openam/statuses/{sha}","languages_url":"https://api.github.com/repos/agco/passport-openam/languages","stargazers_url":"https://api.github.com/repos/agco/passport-openam/stargazers","contributors_url":"https://api.github.com/repos/agco/passport-openam/contributors","subscribers_url":"https://api.github.com/repos/agco/passport-openam/subscribers","subscription_url":"https://api.github.com/repos/agco/passport-openam/subscription","commits_url":"https://api.github.com/repos/agco/passport-openam/commits{/sha}","git_commits_url":"https://api.github.com/repos/agco/passport-openam/git/commits{/sha}","comments_url":"https://api.github.com/repos/agco/passport-openam/comments{/number}","issue_comment_url":"https://api.github.com/repos/agco/passport-openam/issues/comments{/number}","contents_url":"https://api.github.com/repos/agco/passport-openam/contents/{+path}","compare_url":"https://api.github.com/repos/agco/passport-openam/compare/{base}...{head}","merges_url":"https://api.github.com/repos/agco/passport-openam/merges","archive_url":"https://api.github.com/repos/agco/passport-openam/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/agco/passport-openam/downloads","issues_url":"https://api.github.com/repos/agco/passport-openam/issues{/number}","pulls_url":"https://api.github.com/repos/agco/passport-openam/pulls{/number}","milestones_url":"https://api.github.com/repos/agco/passport-openam/milestones{/number}","notifications_url":"https://api.github.com/repos/agco/passport-openam/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/agco/passport-openam/labels{/name}","releases_url":"https://api.github.com/repos/agco/passport-openam/releases{/id}","created_at":"2015-04-07T10:33:31Z","updated_at":"2015-04-20T20:05:00Z","pushed_at":"2015-04-23T20:39:24Z","git_url":"git://github.com/agco/passport-openam.git","ssh_url":"git@github.com:agco/passport-openam.git","clone_url":"https://github.com/agco/passport-openam.git","svn_url":"https://github.com/agco/passport-openam","homepage":null,"size":156,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/agco/passport-openam/pulls/1"},"html":{"href":"https://github.com/agco/passport-openam/pull/1"},"issue":{"href":"https://api.github.com/repos/agco/passport-openam/issues/1"},"comments":{"href":"https://api.github.com/repos/agco/passport-openam/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/agco/passport-openam/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/agco/passport-openam/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/agco/passport-openam/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/agco/passport-openam/statuses/1530678e4daf5a634498ce11f0594b967a65cffd"}}}}