{"action":"created","comment":{"url":"https://api.github.com/repos/stormpath/express-stormpath/pulls/comments/51841362","id":51841362,"diff_hunk":"@@ -18,31 +21,78 @@ module.exports = function (req, res) {\n   var config = req.app.get('stormpathConfig');\n   var logger = req.app.get('stormpathLogger');\n \n-  application.handleIdSiteCallback(req.originalUrl, function (err, result) {\n+  var params = req.query || {};\n+  var stormpathToken = params.jwtResponse || '';\n+  var assertionAuthenticator = new stormpath.StormpathAssertionAuthenticator(application);\n+\n+  assertionAuthenticator.authenticate(stormpathToken, function (err) {\n     if (err) {\n-      logger.info('While attempting to authenticate a user via ID site, the callback verification failed.');\n-      return res.status(500).end(err.toString());\n+      logger.info('During an IdSite login attempt, we were unable to verify the JWT response.');\n+      return res.status(err.status || 400).json(err);\n     }\n \n-    var idSiteNextUri = config.web.idSite.nextUri;\n+    var parsedToken = nJwt.verify(stormpathToken, config.client.apiKey.secret);\n+    var tokenStatus = parsedToken.body.status;\n \n-    switch (result.status) {\n-      case 'LOGOUT':\n-        middleware.deleteCookies(req, res);\n-        res.redirect(302, idSiteNextUri);\n-        break;\n+    function redirectNext() {\n+      var nextUri = config.web.idSite.nextUri;\n+      var nextQueryPath = url.parse(params.next || '').path;\n+      res.redirect(302, nextQueryPath || nextUri);\n+    }\n+\n+    function authenticateToken(callback) {\n+      var stormpathTokenAuthenticator = new stormpath.OAuthStormpathTokenAuthenticator(application);\n+\n+      stormpathTokenAuthenticator.authenticate({ stormpath_token: stormpathToken }, function (err, authenticationResult) {\n+        if (err) {\n+          logger.info('During an IdSite login attempt, we were unable to create a Stormpath session.');\n+          return res.status(err.status || 400).json(err);\n+        }\n+\n+        helpers.createSession(authenticationResult, authenticationResult.account, req, res);\n+\n+        callback();\n+      });\n+    }\n+\n+    function handleAuthRequest(type, callback) {\n+      var handler = config['post' + type + 'Handler'];","path":"lib/controllers/id-site-verify.js","position":61,"original_position":61,"commit_id":"634a2933aba9d343393984843bf7de9b6c973c18","original_commit_id":"634a2933aba9d343393984843bf7de9b6c973c18","user":{"login":"typerandom","id":1331778,"avatar_url":"https://avatars.githubusercontent.com/u/1331778?v=3","gravatar_id":"","url":"https://api.github.com/users/typerandom","html_url":"https://github.com/typerandom","followers_url":"https://api.github.com/users/typerandom/followers","following_url":"https://api.github.com/users/typerandom/following{/other_user}","gists_url":"https://api.github.com/users/typerandom/gists{/gist_id}","starred_url":"https://api.github.com/users/typerandom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/typerandom/subscriptions","organizations_url":"https://api.github.com/users/typerandom/orgs","repos_url":"https://api.github.com/users/typerandom/repos","events_url":"https://api.github.com/users/typerandom/events{/privacy}","received_events_url":"https://api.github.com/users/typerandom/received_events","type":"User","site_admin":false},"body":"Yeah, I fully agree with that reasoning. Will change that.","created_at":"2016-02-04T08:23:18Z","updated_at":"2016-02-04T08:23:18Z","html_url":"https://github.com/stormpath/express-stormpath/pull/296#discussion_r51841362","pull_request_url":"https://api.github.com/repos/stormpath/express-stormpath/pulls/296","_links":{"self":{"href":"https://api.github.com/repos/stormpath/express-stormpath/pulls/comments/51841362"},"html":{"href":"https://github.com/stormpath/express-stormpath/pull/296#discussion_r51841362"},"pull_request":{"href":"https://api.github.com/repos/stormpath/express-stormpath/pulls/296"}}},"pull_request":{"url":"https://api.github.com/repos/stormpath/express-stormpath/pulls/296","id":57877089,"html_url":"https://github.com/stormpath/express-stormpath/pull/296","diff_url":"https://github.com/stormpath/express-stormpath/pull/296.diff","patch_url":"https://github.com/stormpath/express-stormpath/pull/296.patch","issue_url":"https://api.github.com/repos/stormpath/express-stormpath/issues/296","number":296,"state":"open","locked":false,"title":"Feature: Replace ID site token with Stormpath token","user":{"login":"typerandom","id":1331778,"avatar_url":"https://avatars.githubusercontent.com/u/1331778?v=3","gravatar_id":"","url":"https://api.github.com/users/typerandom","html_url":"https://github.com/typerandom","followers_url":"https://api.github.com/users/typerandom/followers","following_url":"https://api.github.com/users/typerandom/following{/other_user}","gists_url":"https://api.github.com/users/typerandom/gists{/gist_id}","starred_url":"https://api.github.com/users/typerandom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/typerandom/subscriptions","organizations_url":"https://api.github.com/users/typerandom/orgs","repos_url":"https://api.github.com/users/typerandom/repos","events_url":"https://api.github.com/users/typerandom/events{/privacy}","received_events_url":"https://api.github.com/users/typerandom/received_events","type":"User","site_admin":false},"body":"Replaces the ID site token with a Stormpath OAuth access/refresh token.\r\n\r\nRequires https://github.com/stormpath/stormpath-sdk-node/pull/362 to be merged.\r\n\r\nFixes #251.","created_at":"2016-02-01T18:08:25Z","updated_at":"2016-02-04T08:23:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"714eb99b19341fb7641704240797587372908ece","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/stormpath/express-stormpath/pulls/296/commits","review_comments_url":"https://api.github.com/repos/stormpath/express-stormpath/pulls/296/comments","review_comment_url":"https://api.github.com/repos/stormpath/express-stormpath/pulls/comments{/number}","comments_url":"https://api.github.com/repos/stormpath/express-stormpath/issues/296/comments","statuses_url":"https://api.github.com/repos/stormpath/express-stormpath/statuses/634a2933aba9d343393984843bf7de9b6c973c18","head":{"label":"stormpath:feature-replace-id-session-with-oauth-tokens","ref":"feature-replace-id-session-with-oauth-tokens","sha":"634a2933aba9d343393984843bf7de9b6c973c18","user":{"login":"stormpath","id":1377453,"avatar_url":"https://avatars.githubusercontent.com/u/1377453?v=3","gravatar_id":"","url":"https://api.github.com/users/stormpath","html_url":"https://github.com/stormpath","followers_url":"https://api.github.com/users/stormpath/followers","following_url":"https://api.github.com/users/stormpath/following{/other_user}","gists_url":"https://api.github.com/users/stormpath/gists{/gist_id}","starred_url":"https://api.github.com/users/stormpath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stormpath/subscriptions","organizations_url":"https://api.github.com/users/stormpath/orgs","repos_url":"https://api.github.com/users/stormpath/repos","events_url":"https://api.github.com/users/stormpath/events{/privacy}","received_events_url":"https://api.github.com/users/stormpath/received_events","type":"Organization","site_admin":false},"repo":{"id":21433270,"name":"express-stormpath","full_name":"stormpath/express-stormpath","owner":{"login":"stormpath","id":1377453,"avatar_url":"https://avatars.githubusercontent.com/u/1377453?v=3","gravatar_id":"","url":"https://api.github.com/users/stormpath","html_url":"https://github.com/stormpath","followers_url":"https://api.github.com/users/stormpath/followers","following_url":"https://api.github.com/users/stormpath/following{/other_user}","gists_url":"https://api.github.com/users/stormpath/gists{/gist_id}","starred_url":"https://api.github.com/users/stormpath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stormpath/subscriptions","organizations_url":"https://api.github.com/users/stormpath/orgs","repos_url":"https://api.github.com/users/stormpath/repos","events_url":"https://api.github.com/users/stormpath/events{/privacy}","received_events_url":"https://api.github.com/users/stormpath/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/stormpath/express-stormpath","description":"Build simple, secure web applications with Stormpath and Express!","fork":false,"url":"https://api.github.com/repos/stormpath/express-stormpath","forks_url":"https://api.github.com/repos/stormpath/express-stormpath/forks","keys_url":"https://api.github.com/repos/stormpath/express-stormpath/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stormpath/express-stormpath/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stormpath/express-stormpath/teams","hooks_url":"https://api.github.com/repos/stormpath/express-stormpath/hooks","issue_events_url":"https://api.github.com/repos/stormpath/express-stormpath/issues/events{/number}","events_url":"https://api.github.com/repos/stormpath/express-stormpath/events","assignees_url":"https://api.github.com/repos/stormpath/express-stormpath/assignees{/user}","branches_url":"https://api.github.com/repos/stormpath/express-stormpath/branches{/branch}","tags_url":"https://api.github.com/repos/stormpath/express-stormpath/tags","blobs_url":"https://api.github.com/repos/stormpath/express-stormpath/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stormpath/express-stormpath/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stormpath/express-stormpath/git/refs{/sha}","trees_url":"https://api.github.com/repos/stormpath/express-stormpath/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stormpath/express-stormpath/statuses/{sha}","languages_url":"https://api.github.com/repos/stormpath/express-stormpath/languages","stargazers_url":"https://api.github.com/repos/stormpath/express-stormpath/stargazers","contributors_url":"https://api.github.com/repos/stormpath/express-stormpath/contributors","subscribers_url":"https://api.github.com/repos/stormpath/express-stormpath/subscribers","subscription_url":"https://api.github.com/repos/stormpath/express-stormpath/subscription","commits_url":"https://api.github.com/repos/stormpath/express-stormpath/commits{/sha}","git_commits_url":"https://api.github.com/repos/stormpath/express-stormpath/git/commits{/sha}","comments_url":"https://api.github.com/repos/stormpath/express-stormpath/comments{/number}","issue_comment_url":"https://api.github.com/repos/stormpath/express-stormpath/issues/comments{/number}","contents_url":"https://api.github.com/repos/stormpath/express-stormpath/contents/{+path}","compare_url":"https://api.github.com/repos/stormpath/express-stormpath/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stormpath/express-stormpath/merges","archive_url":"https://api.github.com/repos/stormpath/express-stormpath/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stormpath/express-stormpath/downloads","issues_url":"https://api.github.com/repos/stormpath/express-stormpath/issues{/number}","pulls_url":"https://api.github.com/repos/stormpath/express-stormpath/pulls{/number}","milestones_url":"https://api.github.com/repos/stormpath/express-stormpath/milestones{/number}","notifications_url":"https://api.github.com/repos/stormpath/express-stormpath/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stormpath/express-stormpath/labels{/name}","releases_url":"https://api.github.com/repos/stormpath/express-stormpath/releases{/id}","deployments_url":"https://api.github.com/repos/stormpath/express-stormpath/deployments","created_at":"2014-07-02T17:25:41Z","updated_at":"2016-02-03T01:16:39Z","pushed_at":"2016-02-04T06:10:08Z","git_url":"git://github.com/stormpath/express-stormpath.git","ssh_url":"git@github.com:stormpath/express-stormpath.git","clone_url":"https://github.com/stormpath/express-stormpath.git","svn_url":"https://github.com/stormpath/express-stormpath","homepage":"http://docs.stormpath.com/nodejs/express/","size":14034,"stargazers_count":148,"watchers_count":148,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":62,"mirror_url":null,"open_issues_count":35,"forks":62,"open_issues":35,"watchers":148,"default_branch":"master"}},"base":{"label":"stormpath:master","ref":"master","sha":"7eec6dc791ad5d44d6f119ddbe5acf35fb99b9a5","user":{"login":"stormpath","id":1377453,"avatar_url":"https://avatars.githubusercontent.com/u/1377453?v=3","gravatar_id":"","url":"https://api.github.com/users/stormpath","html_url":"https://github.com/stormpath","followers_url":"https://api.github.com/users/stormpath/followers","following_url":"https://api.github.com/users/stormpath/following{/other_user}","gists_url":"https://api.github.com/users/stormpath/gists{/gist_id}","starred_url":"https://api.github.com/users/stormpath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stormpath/subscriptions","organizations_url":"https://api.github.com/users/stormpath/orgs","repos_url":"https://api.github.com/users/stormpath/repos","events_url":"https://api.github.com/users/stormpath/events{/privacy}","received_events_url":"https://api.github.com/users/stormpath/received_events","type":"Organization","site_admin":false},"repo":{"id":21433270,"name":"express-stormpath","full_name":"stormpath/express-stormpath","owner":{"login":"stormpath","id":1377453,"avatar_url":"https://avatars.githubusercontent.com/u/1377453?v=3","gravatar_id":"","url":"https://api.github.com/users/stormpath","html_url":"https://github.com/stormpath","followers_url":"https://api.github.com/users/stormpath/followers","following_url":"https://api.github.com/users/stormpath/following{/other_user}","gists_url":"https://api.github.com/users/stormpath/gists{/gist_id}","starred_url":"https://api.github.com/users/stormpath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stormpath/subscriptions","organizations_url":"https://api.github.com/users/stormpath/orgs","repos_url":"https://api.github.com/users/stormpath/repos","events_url":"https://api.github.com/users/stormpath/events{/privacy}","received_events_url":"https://api.github.com/users/stormpath/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/stormpath/express-stormpath","description":"Build simple, secure web applications with Stormpath and Express!","fork":false,"url":"https://api.github.com/repos/stormpath/express-stormpath","forks_url":"https://api.github.com/repos/stormpath/express-stormpath/forks","keys_url":"https://api.github.com/repos/stormpath/express-stormpath/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stormpath/express-stormpath/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stormpath/express-stormpath/teams","hooks_url":"https://api.github.com/repos/stormpath/express-stormpath/hooks","issue_events_url":"https://api.github.com/repos/stormpath/express-stormpath/issues/events{/number}","events_url":"https://api.github.com/repos/stormpath/express-stormpath/events","assignees_url":"https://api.github.com/repos/stormpath/express-stormpath/assignees{/user}","branches_url":"https://api.github.com/repos/stormpath/express-stormpath/branches{/branch}","tags_url":"https://api.github.com/repos/stormpath/express-stormpath/tags","blobs_url":"https://api.github.com/repos/stormpath/express-stormpath/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stormpath/express-stormpath/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stormpath/express-stormpath/git/refs{/sha}","trees_url":"https://api.github.com/repos/stormpath/express-stormpath/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stormpath/express-stormpath/statuses/{sha}","languages_url":"https://api.github.com/repos/stormpath/express-stormpath/languages","stargazers_url":"https://api.github.com/repos/stormpath/express-stormpath/stargazers","contributors_url":"https://api.github.com/repos/stormpath/express-stormpath/contributors","subscribers_url":"https://api.github.com/repos/stormpath/express-stormpath/subscribers","subscription_url":"https://api.github.com/repos/stormpath/express-stormpath/subscription","commits_url":"https://api.github.com/repos/stormpath/express-stormpath/commits{/sha}","git_commits_url":"https://api.github.com/repos/stormpath/express-stormpath/git/commits{/sha}","comments_url":"https://api.github.com/repos/stormpath/express-stormpath/comments{/number}","issue_comment_url":"https://api.github.com/repos/stormpath/express-stormpath/issues/comments{/number}","contents_url":"https://api.github.com/repos/stormpath/express-stormpath/contents/{+path}","compare_url":"https://api.github.com/repos/stormpath/express-stormpath/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stormpath/express-stormpath/merges","archive_url":"https://api.github.com/repos/stormpath/express-stormpath/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stormpath/express-stormpath/downloads","issues_url":"https://api.github.com/repos/stormpath/express-stormpath/issues{/number}","pulls_url":"https://api.github.com/repos/stormpath/express-stormpath/pulls{/number}","milestones_url":"https://api.github.com/repos/stormpath/express-stormpath/milestones{/number}","notifications_url":"https://api.github.com/repos/stormpath/express-stormpath/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stormpath/express-stormpath/labels{/name}","releases_url":"https://api.github.com/repos/stormpath/express-stormpath/releases{/id}","deployments_url":"https://api.github.com/repos/stormpath/express-stormpath/deployments","created_at":"2014-07-02T17:25:41Z","updated_at":"2016-02-03T01:16:39Z","pushed_at":"2016-02-04T06:10:08Z","git_url":"git://github.com/stormpath/express-stormpath.git","ssh_url":"git@github.com:stormpath/express-stormpath.git","clone_url":"https://github.com/stormpath/express-stormpath.git","svn_url":"https://github.com/stormpath/express-stormpath","homepage":"http://docs.stormpath.com/nodejs/express/","size":14034,"stargazers_count":148,"watchers_count":148,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":62,"mirror_url":null,"open_issues_count":35,"forks":62,"open_issues":35,"watchers":148,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/stormpath/express-stormpath/pulls/296"},"html":{"href":"https://github.com/stormpath/express-stormpath/pull/296"},"issue":{"href":"https://api.github.com/repos/stormpath/express-stormpath/issues/296"},"comments":{"href":"https://api.github.com/repos/stormpath/express-stormpath/issues/296/comments"},"review_comments":{"href":"https://api.github.com/repos/stormpath/express-stormpath/pulls/296/comments"},"review_comment":{"href":"https://api.github.com/repos/stormpath/express-stormpath/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/stormpath/express-stormpath/pulls/296/commits"},"statuses":{"href":"https://api.github.com/repos/stormpath/express-stormpath/statuses/634a2933aba9d343393984843bf7de9b6c973c18"}}}}