{"action":"created","comment":{"url":"https://api.github.com/repos/talis/persona-node-client/pulls/comments/61061716","id":61061716,"diff_hunk":"@@ -344,55 +344,65 @@ PersonaClient.prototype.validateToken = function (opts, next) {\n  * @param {Object} response - HTTP response object. If you want to validate against a scope (pre-2.0 behavior), provide it as req.params.scope\n  * @callback next - Called with either an error as the first param or \"ok\" as the result in the second param.\n  */\n-PersonaClient.prototype.validateHTTPBearerToken = function (request, response, next) {\n+PersonaClient.prototype.validateHTTPBearerToken = function validateHTTPBearerToken(request, response, next) {\n+    var config = {\n+        token: this._getToken(request),\n+        scope: request.param('scope'),\n+        xRequestId: this.getXRequestId(request),\n+    };\n+\n     if (arguments.length > 3) {\n-        throw \"Usage: validateHTTPBearerToken(request, response, next)\";\n+        throw new Error('Usage: validateHTTPBearerToken(request, response, next)');\n     }\n-    var token = this._getToken(request);\n-    var xRequestId = this.getXRequestId(request);\n \n-    this.validateToken({token: token, scope: request.param(\"scope\"), xRequestId: xRequestId}, function (error, validationResult) {\n+    function callback(error, validationResult) {\n         if (!error) {\n             next(null, validationResult);\n             return;\n         }\n \n-        switch(error) {\n+        switch (error) {\n         case ERROR_TYPES.INVALID_TOKEN:\n             response.status(401);\n             response.json({\n-                \"error\": \"no_token\",\n-                \"error_description\": \"No token supplied\"\n+                'error': 'no_token',\n+                'error_description': 'No token supplied',\n             });\n             break;\n         case ERROR_TYPES.VALIDATION_FAILURE:\n             response.status(401);\n-            response.set(\"Connection\", \"close\");\n+            response.set('Connection', 'close');\n             response.json({\n-                \"error\": \"invalid_token\",\n-                \"error_description\": \"The token is invalid or has expired\"\n+                'error': 'invalid_token',\n+                'error_description': 'The token is invalid or has expired',\n             });\n             break;\n         case ERROR_TYPES.INSUFFICIENT_SCOPE:\n             response.status(403);\n-            response.set(\"Connection\", \"close\");\n+            response.set('Connection', 'close');\n             response.json({\n-                \"error\": \"insufficient_scope\",\n-                \"error_description\": \"The supplied token is missing a required scope\"\n+                'error': 'insufficient_scope',\n+                'error_description': 'The supplied token is missing a required scope',\n             });\n             break;\n         default:\n             response.status(500);\n-            response.set(\"Connection\", \"close\");\n+            response.set('Connection', 'close');\n             response.json({\n-                \"error\": \"unexpected_error\",\n-                \"error_description\": error\n+                'error': 'unexpected_error',\n+                'error_description': error,\n             });\n         }\n \n         next(error, null);\n         return;\n-    });\n+    }\n+\n+    try {\n+        this.validateToken(config, callback);\n+    } catch (exception) {\n+        return callback(ERROR_TYPES.INVALID_TOKEN, null);","path":"index.js","position":79,"original_position":79,"commit_id":"65f2b0e89c3bf555fe452fcdd4c7518163a7e8c6","original_commit_id":"65f2b0e89c3bf555fe452fcdd4c7518163a7e8c6","user":{"login":"markwallsgrove","id":6328824,"avatar_url":"https://avatars.githubusercontent.com/u/6328824?v=3","gravatar_id":"","url":"https://api.github.com/users/markwallsgrove","html_url":"https://github.com/markwallsgrove","followers_url":"https://api.github.com/users/markwallsgrove/followers","following_url":"https://api.github.com/users/markwallsgrove/following{/other_user}","gists_url":"https://api.github.com/users/markwallsgrove/gists{/gist_id}","starred_url":"https://api.github.com/users/markwallsgrove/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markwallsgrove/subscriptions","organizations_url":"https://api.github.com/users/markwallsgrove/orgs","repos_url":"https://api.github.com/users/markwallsgrove/repos","events_url":"https://api.github.com/users/markwallsgrove/events{/privacy}","received_events_url":"https://api.github.com/users/markwallsgrove/received_events","type":"User","site_admin":false},"body":"yep, agreed. This problem related to throwing generic errors.","created_at":"2016-04-26T10:16:45Z","updated_at":"2016-04-26T10:16:45Z","html_url":"https://github.com/talis/persona-node-client/pull/18#discussion_r61061716","pull_request_url":"https://api.github.com/repos/talis/persona-node-client/pulls/18","_links":{"self":{"href":"https://api.github.com/repos/talis/persona-node-client/pulls/comments/61061716"},"html":{"href":"https://github.com/talis/persona-node-client/pull/18#discussion_r61061716"},"pull_request":{"href":"https://api.github.com/repos/talis/persona-node-client/pulls/18"}}},"pull_request":{"url":"https://api.github.com/repos/talis/persona-node-client/pulls/18","id":67859366,"html_url":"https://github.com/talis/persona-node-client/pull/18","diff_url":"https://github.com/talis/persona-node-client/pull/18.diff","patch_url":"https://github.com/talis/persona-node-client/pull/18.patch","issue_url":"https://api.github.com/repos/talis/persona-node-client/issues/18","number":18,"state":"open","locked":false,"title":"90% - No token middleware bug","user":{"login":"markwallsgrove","id":6328824,"avatar_url":"https://avatars.githubusercontent.com/u/6328824?v=3","gravatar_id":"","url":"https://api.github.com/users/markwallsgrove","html_url":"https://github.com/markwallsgrove","followers_url":"https://api.github.com/users/markwallsgrove/followers","following_url":"https://api.github.com/users/markwallsgrove/following{/other_user}","gists_url":"https://api.github.com/users/markwallsgrove/gists{/gist_id}","starred_url":"https://api.github.com/users/markwallsgrove/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markwallsgrove/subscriptions","organizations_url":"https://api.github.com/users/markwallsgrove/orgs","repos_url":"https://api.github.com/users/markwallsgrove/repos","events_url":"https://api.github.com/users/markwallsgrove/events{/privacy}","received_events_url":"https://api.github.com/users/markwallsgrove/received_events","type":"User","site_admin":false},"body":"ValidateToken now throws an exception if `token` is not supplied.\r\nThe token is checked by using `_.isEmpty` (null, \"\", 0, etc). As the\r\ntoken is supplied by the user within the middleware it is possible that\r\nit could be null or a empty string. This will throw an exception that\r\nis not handled correctly.","created_at":"2016-04-26T10:11:22Z","updated_at":"2016-04-26T10:16:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ffa58d46bdd7b218fd5499cacbfe70c1453b2299","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/talis/persona-node-client/pulls/18/commits","review_comments_url":"https://api.github.com/repos/talis/persona-node-client/pulls/18/comments","review_comment_url":"https://api.github.com/repos/talis/persona-node-client/pulls/comments{/number}","comments_url":"https://api.github.com/repos/talis/persona-node-client/issues/18/comments","statuses_url":"https://api.github.com/repos/talis/persona-node-client/statuses/65f2b0e89c3bf555fe452fcdd4c7518163a7e8c6","head":{"label":"talis:no_token_middleware_bug","ref":"no_token_middleware_bug","sha":"65f2b0e89c3bf555fe452fcdd4c7518163a7e8c6","user":{"login":"talis","id":181416,"avatar_url":"https://avatars.githubusercontent.com/u/181416?v=3","gravatar_id":"","url":"https://api.github.com/users/talis","html_url":"https://github.com/talis","followers_url":"https://api.github.com/users/talis/followers","following_url":"https://api.github.com/users/talis/following{/other_user}","gists_url":"https://api.github.com/users/talis/gists{/gist_id}","starred_url":"https://api.github.com/users/talis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/talis/subscriptions","organizations_url":"https://api.github.com/users/talis/orgs","repos_url":"https://api.github.com/users/talis/repos","events_url":"https://api.github.com/users/talis/events{/privacy}","received_events_url":"https://api.github.com/users/talis/received_events","type":"Organization","site_admin":false},"repo":{"id":14619372,"name":"persona-node-client","full_name":"talis/persona-node-client","owner":{"login":"talis","id":181416,"avatar_url":"https://avatars.githubusercontent.com/u/181416?v=3","gravatar_id":"","url":"https://api.github.com/users/talis","html_url":"https://github.com/talis","followers_url":"https://api.github.com/users/talis/followers","following_url":"https://api.github.com/users/talis/following{/other_user}","gists_url":"https://api.github.com/users/talis/gists{/gist_id}","starred_url":"https://api.github.com/users/talis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/talis/subscriptions","organizations_url":"https://api.github.com/users/talis/orgs","repos_url":"https://api.github.com/users/talis/repos","events_url":"https://api.github.com/users/talis/events{/privacy}","received_events_url":"https://api.github.com/users/talis/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/talis/persona-node-client","description":"This is a node client library for Persona supporting generation, validation and caching of Oauth Tokens","fork":false,"url":"https://api.github.com/repos/talis/persona-node-client","forks_url":"https://api.github.com/repos/talis/persona-node-client/forks","keys_url":"https://api.github.com/repos/talis/persona-node-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/talis/persona-node-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/talis/persona-node-client/teams","hooks_url":"https://api.github.com/repos/talis/persona-node-client/hooks","issue_events_url":"https://api.github.com/repos/talis/persona-node-client/issues/events{/number}","events_url":"https://api.github.com/repos/talis/persona-node-client/events","assignees_url":"https://api.github.com/repos/talis/persona-node-client/assignees{/user}","branches_url":"https://api.github.com/repos/talis/persona-node-client/branches{/branch}","tags_url":"https://api.github.com/repos/talis/persona-node-client/tags","blobs_url":"https://api.github.com/repos/talis/persona-node-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/talis/persona-node-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/talis/persona-node-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/talis/persona-node-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/talis/persona-node-client/statuses/{sha}","languages_url":"https://api.github.com/repos/talis/persona-node-client/languages","stargazers_url":"https://api.github.com/repos/talis/persona-node-client/stargazers","contributors_url":"https://api.github.com/repos/talis/persona-node-client/contributors","subscribers_url":"https://api.github.com/repos/talis/persona-node-client/subscribers","subscription_url":"https://api.github.com/repos/talis/persona-node-client/subscription","commits_url":"https://api.github.com/repos/talis/persona-node-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/talis/persona-node-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/talis/persona-node-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/talis/persona-node-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/talis/persona-node-client/contents/{+path}","compare_url":"https://api.github.com/repos/talis/persona-node-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/talis/persona-node-client/merges","archive_url":"https://api.github.com/repos/talis/persona-node-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/talis/persona-node-client/downloads","issues_url":"https://api.github.com/repos/talis/persona-node-client/issues{/number}","pulls_url":"https://api.github.com/repos/talis/persona-node-client/pulls{/number}","milestones_url":"https://api.github.com/repos/talis/persona-node-client/milestones{/number}","notifications_url":"https://api.github.com/repos/talis/persona-node-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/talis/persona-node-client/labels{/name}","releases_url":"https://api.github.com/repos/talis/persona-node-client/releases{/id}","deployments_url":"https://api.github.com/repos/talis/persona-node-client/deployments","created_at":"2013-11-22T14:11:31Z","updated_at":"2016-02-02T13:59:33Z","pushed_at":"2016-04-26T10:12:51Z","git_url":"git://github.com/talis/persona-node-client.git","ssh_url":"git@github.com:talis/persona-node-client.git","clone_url":"https://github.com/talis/persona-node-client.git","svn_url":"https://github.com/talis/persona-node-client","homepage":null,"size":295,"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":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"talis:master","ref":"master","sha":"684df21651af7a16160b2fbc2923ef2045524691","user":{"login":"talis","id":181416,"avatar_url":"https://avatars.githubusercontent.com/u/181416?v=3","gravatar_id":"","url":"https://api.github.com/users/talis","html_url":"https://github.com/talis","followers_url":"https://api.github.com/users/talis/followers","following_url":"https://api.github.com/users/talis/following{/other_user}","gists_url":"https://api.github.com/users/talis/gists{/gist_id}","starred_url":"https://api.github.com/users/talis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/talis/subscriptions","organizations_url":"https://api.github.com/users/talis/orgs","repos_url":"https://api.github.com/users/talis/repos","events_url":"https://api.github.com/users/talis/events{/privacy}","received_events_url":"https://api.github.com/users/talis/received_events","type":"Organization","site_admin":false},"repo":{"id":14619372,"name":"persona-node-client","full_name":"talis/persona-node-client","owner":{"login":"talis","id":181416,"avatar_url":"https://avatars.githubusercontent.com/u/181416?v=3","gravatar_id":"","url":"https://api.github.com/users/talis","html_url":"https://github.com/talis","followers_url":"https://api.github.com/users/talis/followers","following_url":"https://api.github.com/users/talis/following{/other_user}","gists_url":"https://api.github.com/users/talis/gists{/gist_id}","starred_url":"https://api.github.com/users/talis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/talis/subscriptions","organizations_url":"https://api.github.com/users/talis/orgs","repos_url":"https://api.github.com/users/talis/repos","events_url":"https://api.github.com/users/talis/events{/privacy}","received_events_url":"https://api.github.com/users/talis/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/talis/persona-node-client","description":"This is a node client library for Persona supporting generation, validation and caching of Oauth Tokens","fork":false,"url":"https://api.github.com/repos/talis/persona-node-client","forks_url":"https://api.github.com/repos/talis/persona-node-client/forks","keys_url":"https://api.github.com/repos/talis/persona-node-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/talis/persona-node-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/talis/persona-node-client/teams","hooks_url":"https://api.github.com/repos/talis/persona-node-client/hooks","issue_events_url":"https://api.github.com/repos/talis/persona-node-client/issues/events{/number}","events_url":"https://api.github.com/repos/talis/persona-node-client/events","assignees_url":"https://api.github.com/repos/talis/persona-node-client/assignees{/user}","branches_url":"https://api.github.com/repos/talis/persona-node-client/branches{/branch}","tags_url":"https://api.github.com/repos/talis/persona-node-client/tags","blobs_url":"https://api.github.com/repos/talis/persona-node-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/talis/persona-node-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/talis/persona-node-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/talis/persona-node-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/talis/persona-node-client/statuses/{sha}","languages_url":"https://api.github.com/repos/talis/persona-node-client/languages","stargazers_url":"https://api.github.com/repos/talis/persona-node-client/stargazers","contributors_url":"https://api.github.com/repos/talis/persona-node-client/contributors","subscribers_url":"https://api.github.com/repos/talis/persona-node-client/subscribers","subscription_url":"https://api.github.com/repos/talis/persona-node-client/subscription","commits_url":"https://api.github.com/repos/talis/persona-node-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/talis/persona-node-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/talis/persona-node-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/talis/persona-node-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/talis/persona-node-client/contents/{+path}","compare_url":"https://api.github.com/repos/talis/persona-node-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/talis/persona-node-client/merges","archive_url":"https://api.github.com/repos/talis/persona-node-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/talis/persona-node-client/downloads","issues_url":"https://api.github.com/repos/talis/persona-node-client/issues{/number}","pulls_url":"https://api.github.com/repos/talis/persona-node-client/pulls{/number}","milestones_url":"https://api.github.com/repos/talis/persona-node-client/milestones{/number}","notifications_url":"https://api.github.com/repos/talis/persona-node-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/talis/persona-node-client/labels{/name}","releases_url":"https://api.github.com/repos/talis/persona-node-client/releases{/id}","deployments_url":"https://api.github.com/repos/talis/persona-node-client/deployments","created_at":"2013-11-22T14:11:31Z","updated_at":"2016-02-02T13:59:33Z","pushed_at":"2016-04-26T10:12:51Z","git_url":"git://github.com/talis/persona-node-client.git","ssh_url":"git@github.com:talis/persona-node-client.git","clone_url":"https://github.com/talis/persona-node-client.git","svn_url":"https://github.com/talis/persona-node-client","homepage":null,"size":295,"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":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/talis/persona-node-client/pulls/18"},"html":{"href":"https://github.com/talis/persona-node-client/pull/18"},"issue":{"href":"https://api.github.com/repos/talis/persona-node-client/issues/18"},"comments":{"href":"https://api.github.com/repos/talis/persona-node-client/issues/18/comments"},"review_comments":{"href":"https://api.github.com/repos/talis/persona-node-client/pulls/18/comments"},"review_comment":{"href":"https://api.github.com/repos/talis/persona-node-client/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/talis/persona-node-client/pulls/18/commits"},"statuses":{"href":"https://api.github.com/repos/talis/persona-node-client/statuses/65f2b0e89c3bf555fe452fcdd4c7518163a7e8c6"}}}}