{"action":"created","issue":{"url":"https://api.github.com/repos/google/google-auth-library-nodejs/issues/92","repository_url":"https://api.github.com/repos/google/google-auth-library-nodejs","labels_url":"https://api.github.com/repos/google/google-auth-library-nodejs/issues/92/labels{/name}","comments_url":"https://api.github.com/repos/google/google-auth-library-nodejs/issues/92/comments","events_url":"https://api.github.com/repos/google/google-auth-library-nodejs/issues/92/events","html_url":"https://github.com/google/google-auth-library-nodejs/pull/92","id":171281177,"number":92,"title":"googleauth.js change JWT constructor call","user":{"login":"cristiancavalli","id":4976075,"avatar_url":"https://avatars.githubusercontent.com/u/4976075?v=3","gravatar_id":"","url":"https://api.github.com/users/cristiancavalli","html_url":"https://github.com/cristiancavalli","followers_url":"https://api.github.com/users/cristiancavalli/followers","following_url":"https://api.github.com/users/cristiancavalli/following{/other_user}","gists_url":"https://api.github.com/users/cristiancavalli/gists{/gist_id}","starred_url":"https://api.github.com/users/cristiancavalli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cristiancavalli/subscriptions","organizations_url":"https://api.github.com/users/cristiancavalli/orgs","repos_url":"https://api.github.com/users/cristiancavalli/repos","events_url":"https://api.github.com/users/cristiancavalli/events{/privacy}","received_events_url":"https://api.github.com/users/cristiancavalli/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/google/google-auth-library-nodejs/labels/cla:%20yes","name":"cla: yes","color":"009800"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-08-15T22:57:57Z","updated_at":"2016-08-15T22:59:27Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/google/google-auth-library-nodejs/pulls/92","html_url":"https://github.com/google/google-auth-library-nodejs/pull/92","diff_url":"https://github.com/google/google-auth-library-nodejs/pull/92.diff","patch_url":"https://github.com/google/google-auth-library-nodejs/pull/92.patch"},"body":"Given the following code with a valid path for `keyfilePath`:\r\n\r\n```JS\r\nvar keyfilePath = './path/to/my/keyfile.json';\r\nvar stream = require('fs').createReadStream(keyFilePath);\r\nvar GoogleAuth = require('google-auth-library');\r\nvar ga = new GoogleAuth();\r\n\r\nga.fromStream(keyfilePath, function (err, result){\r\n  if (err) {\r\n    console.error('error:', err);\r\n  } else {\r\n    console.log('result:', result);\r\n  }\r\n});\r\n```\r\n\r\nI would expect to see that error is empty but I actually get:\r\n\r\n```JS\r\nTypeError: that.JWTClient is not a constructor\r\n    at GoogleAuth.fromJSON (/Users/cristiancavall/googlesrc/cloud-diagnostics-common-nodejs/node_modules/google-auth-library/lib/auth/googleauth.js:306:17)\r\n    at ReadStream.<anonymous> (/Users/cristiancavall/googlesrc/cloud-diagnostics-common-nodejs/node_modules/google-auth-library/lib/auth/googleauth.js:344:12)\r\n    at emitNone (events.js:91:20)\r\n    at ReadStream.emit (events.js:185:7)\r\n    at endReadableNT (_stream_readable.js:975:12)\r\n    at _combinedTickCallback (internal/process/next_tick.js:74:11)\r\n    at process._tickCallback (internal/process/next_tick.js:98:9)\r\n```\r\n\r\nCode in question:\r\n\r\n```JS\r\nif (json.type === 'authorized_user') {\r\n  client = new that.UserRefreshClient();\r\n} else {\r\n  client = new that.JWTClient();\r\n}\r\n```\r\n\r\nSolution: Use the constructor stored in the prototype\r\n\r\n```JS\r\n/**\r\n * Convenience field mapping in the JWT credential type.\r\n */\r\nGoogleAuth.prototype.JWT = require('./jwtclient.js');\r\n\r\n/* ... */\r\n\r\nif (json.type === 'authorized_user') {\r\n  client = new that.UserRefreshClient();\r\n} else {\r\n  client = new that.JWT();\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/google/google-auth-library-nodejs/issues/comments/239954411","html_url":"https://github.com/google/google-auth-library-nodejs/pull/92#issuecomment-239954411","issue_url":"https://api.github.com/repos/google/google-auth-library-nodejs/issues/92","id":239954411,"user":{"login":"coveralls","id":2354108,"avatar_url":"https://avatars.githubusercontent.com/u/2354108?v=3","gravatar_id":"","url":"https://api.github.com/users/coveralls","html_url":"https://github.com/coveralls","followers_url":"https://api.github.com/users/coveralls/followers","following_url":"https://api.github.com/users/coveralls/following{/other_user}","gists_url":"https://api.github.com/users/coveralls/gists{/gist_id}","starred_url":"https://api.github.com/users/coveralls/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coveralls/subscriptions","organizations_url":"https://api.github.com/users/coveralls/orgs","repos_url":"https://api.github.com/users/coveralls/repos","events_url":"https://api.github.com/users/coveralls/events{/privacy}","received_events_url":"https://api.github.com/users/coveralls/received_events","type":"User","site_admin":false},"created_at":"2016-08-15T22:59:27Z","updated_at":"2016-08-15T22:59:27Z","body":"\n[![Coverage Status](https://coveralls.io/builds/7459926/badge)](https://coveralls.io/builds/7459926)\n\nCoverage remained the same at 92.365% when pulling **2c0154ebadbeef0ca6c1221874fbb3aa1f9c2344 on cristiancavalli:fix_from_stream** into **6f9838e7931899804ab4254cbb5d97dcad0f82f1 on google:master**.\n"}}
{"actor":{"display_login":"coveralls"}}