我正在开发一个node.js
服务器应用程序,该应用程序在localhost:8080
上运行。我正在以两种方式进行登录请求,其中只有一种正在运行。我猜测问题出在req
对象上。
1)我通过Postman Chrome扩展程序发送请求。
这样一切正常。我已通过身份验证并重定向到主页。
2)我使用curl
手动执行此操作,但无法对用户进行身份验证(req.isAuthenticated()
返回false
,我无法访问任何需要user
权限的路由。我使用的命令是:
curl -X POST --header "Content-Type: application/x-www-form-urlencoded" -d "email=some.email%40gmail.com&password=somePass" "http://localhost:8080/login"
以下是我的diff
个对象的req
:
30c30
< { fd: 17,
---
> { fd: 18,
90c90
< bytesRead: 645,
---
> bytesRead: 466,
98c98
< _connections: 1,
---
> _connections: 2,
108,110c108,136
< _idleNext: { _idleNext: [Circular], _idlePrev: [Circular] },
< _idlePrev: { _idleNext: [Circular], _idlePrev: [Circular] },
< _idleStart: 1446646833256,
---
> _idleNext:
> { _connecting: false,
> _handle: [Object],
> _readableState: [Object],
> readable: true,
> domain: null,
> _events: [Object],
> _maxListeners: 10,
> _writableState: [Object],
> writable: true,
> allowHalfOpen: true,
> onend: [Function],
> destroyed: false,
> errorEmitted: false,
> bytesRead: 1112,
> _bytesDispatched: 1772,
> _pendingData: null,
> _pendingEncoding: '',
> server: [Object],
> _idleTimeout: 120000,
> _idleNext: [Object],
> _idlePrev: [Circular],
> _idleStart: 1446646833575,
> parser: [Object],
> ondata: [Function],
> _paused: false,
> _httpMessage: null },
> _idlePrev: { _idleNext: [Circular], _idlePrev: [Object] },
> _idleStart: 1446646871908,
153c179
< { fd: 17,
---
> { fd: 18,
213c239
< bytesRead: 645,
---
> bytesRead: 466,
221c247
< _connections: 1,
---
> _connections: 2,
231,233c257,285
< _idleNext: { _idleNext: [Circular], _idlePrev: [Circular] },
< _idlePrev: { _idleNext: [Circular], _idlePrev: [Circular] },
< _idleStart: 1446646833256,
---
> _idleNext:
> { _connecting: false,
> _handle: [Object],
> _readableState: [Object],
> readable: true,
> domain: null,
> _events: [Object],
> _maxListeners: 10,
> _writableState: [Object],
> writable: true,
> allowHalfOpen: true,
> onend: [Function],
> destroyed: false,
> errorEmitted: false,
> bytesRead: 1112,
> _bytesDispatched: 1772,
> _pendingData: null,
> _pendingEncoding: '',
> server: [Object],
> _idleTimeout: 120000,
> _idleNext: [Object],
> _idlePrev: [Circular],
> _idleStart: 1446646833575,
> parser: [Object],
> ondata: [Function],
> _paused: false,
> _httpMessage: null },
> _idlePrev: { _idleNext: [Circular], _idlePrev: [Object] },
> _idleStart: 1446646871908,
279,281c331
< 'cache-control': 'no-cache',
< origin: 'chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop',
< 'content-type': 'application/x-www-form-urlencoded',
---
> origin: 'http://localhost:8081',
283c333
< 'postman-token': '18ad28a2-c866-0b01-3790-42e7f88be021',
---
> 'content-type': 'application/x-www-form-urlencoded',
284a335
> referer: 'http://localhost:8081/',
286,287c337
< 'accept-language': 'pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4',
< cookie: 'connect.sid=s%3AP2RZKo9-hOSz1N29dFS5SUH_XGMHSxOu.SgxDDkHPhKwz2wbD4SS%2FGQAHV6QiBXAJrpezNedo6FA' },
---
> 'accept-language': 'pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4' },
297c347
< { fd: 17,
---
> { fd: 18,
357c407
< bytesRead: 645,
---
> bytesRead: 466,
365c415
< _connections: 1,
---
> _connections: 2,
375,377c425,453
< _idleNext: { _idleNext: [Circular], _idlePrev: [Circular] },
< _idlePrev: { _idleNext: [Circular], _idlePrev: [Circular] },
< _idleStart: 1446646833256,
---
> _idleNext:
> { _connecting: false,
> _handle: [Object],
> _readableState: [Object],
> readable: true,
> domain: null,
> _events: [Object],
> _maxListeners: 10,
> _writableState: [Object],
> writable: true,
> allowHalfOpen: true,
> onend: [Function],
> destroyed: false,
> errorEmitted: false,
> bytesRead: 1112,
> _bytesDispatched: 1772,
> _pendingData: null,
> _pendingEncoding: '',
> server: [Object],
> _idleTimeout: 120000,
> _idleNext: [Object],
> _idlePrev: [Circular],
> _idleStart: 1446646833575,
> parser: [Object],
> ondata: [Function],
> _paused: false,
> _httpMessage: null },
> _idlePrev: { _idleNext: [Circular], _idlePrev: [Object] },
> _idleStart: 1446646871908,
473c549
< bytesRead: 645,
---
> bytesRead: 466,
481c557
< _idleStart: 1446646833256,
---
> _idleStart: 1446646871908,
500c576
< bytesRead: 645,
---
> bytesRead: 466,
508c584
< _idleStart: 1446646833256,
---
> _idleStart: 1446646871908,
515c591
< 'access-control-allow-origin': 'chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop',
---
> 'access-control-allow-origin': 'http://localhost:8081',
535c611
< cookies: { 'connect.sid': 's:P2RZKo9-hOSz1N29dFS5SUH_XGMHSxOu.SgxDDkHPhKwz2wbD4SS/GQAHV6QiBXAJrpezNedo6FA' },
---
> cookies: {},
552c628
< { sessions: {},
---
> { sessions: { 'T2mMlB997N-CA371f0kp1kHMiEzc_wTE': '{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"passport":{"user":{"id":"55dde27a0f6ff71b72dc7981","active":true,"employment":[{"employee":{"_id":"5605250fcac9a42f0e4124bd","createdAt":"2015-09-13T10:11:12.345Z","schoolId":"55d1e957daea17d3e90a3c50","userId":"55dde27a0f6ff71b72dc7981","timesOff":[{"timeFrom":"2015-11-11T16:11:32.714Z","timeTo":"2015-11-27T16:11:32.714Z","_id":"5630f1350c2efb2e54206aaa"}],"specialties":[],"permissions":["manager"]},"school":{"_id":"55d1e957daea17d3e90a3c50","address":{"zipcode":35665,"streetNum":11,"street":"Main Str.","country":"Italy","city":"Milano"},"contacts":{"phone":"123-456-789"},"email":"email@example.com","logo":"someURL","name":"Another sample ski & snowboard school","resortId":"55ddd14348c851b305cfa2a6","active":true,"openingHours":["7-14","4-21","7-18","2-22","N/A","N/A","N/A"],"defaultMeetingPoints":[{"name":"Black horse pass","geo":{"lat":46.462209,"lng":10.372391}}]}}],"roles":["user"]}}}' },
555c631
< sessionID: 'T2mMlB997N-CA371f0kp1kHMiEzc_wTE',
---
> sessionID: 'u4Z31P-B6qsPneDfj_6vIgd8hg0UdX-g',
(作为第一个 - 顶级文件的工作)。
有什么想法吗?
答案 0 :(得分:1)
如果我不得不猜测这是因为你的cURL请求cookies need to be enabled。
尝试将--cookie
选项添加到您的curl请求中,看看是否有帮助?
命令看起来与此类似:
curl -X POST --cookie ./cookie.txt --header "Content-Type: application/x-www-form-urlencoded" -d "email=some.email%40gmail.com&password=somePass" "http://localhost:8080/login"