【发布时间】:2017-07-24 19:51:49
【问题描述】:
我正在使用 Auth0 并尝试获取 AccessToken。但我遇到了难题。 我怎么解决这个问题? 我遇到了这样的错误:
E:\sample projects\Building-API\movieanalyst-website\server.js:27
if(req.body.access_token){
^
TypeError: Cannot read property 'access_token' of undefined
at E:\sample projects\Building-API\movieanalyst-website\server.js:27:18
at Request.callback (E:\sample projects\Building-API\movieanalyst-website\node_modules\superagent\lib\node\index.js:688:3)
at E:\sample projects\Building-API\movieanalyst-website\node_modules\superagent\lib\node\index.js:883:18
at IncomingMessage.<anonymous> (E:\sample projects\Building-API\movieanalyst-website\node_modules\superagent\lib\node\parsers\json.js:16:7)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:188:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
npm ERR! Windows_NT 10.0.10240
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v7.9.0
npm ERR! npm v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! movieanalyst-website@1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the movieanalyst-website@1.0.0 start script 'node server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the movieanalyst-website package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs movieanalyst-website
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls movieanalyst-website
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\Assassin\AppData\Roaming\npm-cache\_logs\2017-07-24T11_28_24_478Z-debug.log
根据报错,代码是这样的
function getAccessToken(req, res, next) {
request
.post('https://shinji-sakai.auth0.com/oauth/token')
.send(authData)
.end(function(err, res) {
if(req.body.access_token){
req.access_token = res.body.access_token;
next();
} else {
res.send(401, 'Unauthorized');
}
})
}
请给我解决这个问题的方法。 谢谢:)
【问题讨论】:
-
你研究过错误信息的含义吗?到目前为止,您执行了哪些基本调试步骤?