bnoguchi/mongoose-auth

Github example crashing with "Cannot read property 'name' of undefined"

pedrogk opened this issue · 4 comments

Hello. I am running the example of mongoose-auth and getting an error when trying to authenticate with github. I've already tried password, facebook and twitter without a problem, but in github it crashes. Here is the complete trace:


$node server.js
starting step - getAuthUri
...finished step
starting step - requestAuthUri
...finished step
starting step - getCode
...finished step
starting step - getAccessToken
...finished step
starting step - fetchOAuthUser
...finished step
starting step - getSession
...finished step
starting step - findOrCreateUser

node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot read property 'name' of undefined
at Function.createWithGithub (/home/pedro/Projects/talento/sg/sgtalento/node_modules/mongoose-auth/lib/modules/github/plugin.js:37:32)
at Promise. (/home/pedro/Projects/talento/sg/sgtalento/node_modules/mongoose-auth/lib/modules/github/everyauth.js:11:21)
at Promise. (/home/pedro/Projects/talento/sg/sgtalento/node_modules/mongoose/lib/promise.js:120:8)
at Promise. (events.js:67:17)
at Promise.emit (/home/pedro/Projects/talento/sg/sgtalento/node_modules/mongoose/lib/promise.js:59:38)
at Promise.complete (/home/pedro/Projects/talento/sg/sgtalento/node_modules/mongoose/lib/promise.js:70:20)
at /home/pedro/Projects/talento/sg/sgtalento/node_modules/mongoose/lib/query.js:1078:30
at /home/pedro/Projects/talento/sg/sgtalento/node_modules/mongoose/lib/utils.js:408:16
at /home/pedro/Projects/talento/sg/sgtalento/node_modules/mongoose/node_modules/mongodb/lib/mongodb/collection.js:886:5
at /home/pedro/Projects/talento/sg/sgtalento/node_modules/mongoose/node_modules/mongodb/lib/mongodb/cursor.js:129:9


Could anybody check if you get the same error when trying to run the example? Remember you have to add an alias of local.host that points to 127.0.0.1

Could it be related to the security problems that github had some weeks ago and as a result they tightened up something and mongoose-auth wasn't updated?

I'm getting this as well. If you look at https://github.com/bnoguchi/mongoose-auth/blob/master/lib/modules/github/plugin.js it could be that github is no longer returning the 'plan' property/object. Probably, this mongooseAuth module should be a little more lenient on properties not directly relevant to authorization

Note, github auth is broken now in the example code as well, same issue, and from the looks of it (console printing the ghUser object) the plan property is not being returned

Solved: need to add a "scope" property to your github everyauth config. Eg:

github: {
  everyauth: {
      scope: 'user'
    , myHostname: 'http://local.host:3000'
    , appId: conf.github.appId
    , appSecret: conf.github.appSecret
    , redirectPath: '/'
  }
}

With respect to the issue, I would remove the implicit user scope dependency that mongooseAuth has when it tries to access private data

Yes, that fixes it.