首先,感谢您的回复。我尝试使用nodeJS创建REST API,我认为oAuth2是根据我的系统对用户进行身份验证的最佳方式。
用户存储在LDAP中,api密钥保存在MySQL引擎上。客户帐户代码也将存储在MySQL中。所有过程都正常,用户已通过身份验证,API令牌已保存在MySQL中,但当我尝试使用此令牌时,passport拒绝对我的请求进行身份验证并返回:
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (http.js:691:11)
at ServerResponse.res.setHeader (/home/lolostates/Developpement/nodejs/oauth2/test/node_modules/express/node_modules/connect/lib/patch.js:62:20)
at ServerResponse.res.header (/home/lolostates/Developpement/nodejs/oauth2/test/node_modules/express/lib/response.js:280:8)
at ServerResponse.res.json (/home/lolostates/Developpement/nodejs/oauth2/test/node_modules/express/lib/response.js:135:8)
at exports.info (/home/lolostates/Developpement/nodejs/oauth2/test/user.js:13:9)
at callbacks (/home/lolostates/Developpement/nodejs/oauth2/test/node_modules/express/lib/router/index.js:272:11)
at complete (/home/lolostates/Developpement/nodejs/oauth2/test/node_modules/passport/lib/passport/middleware/authenticate.js:218:13)
at /home/lolostates/Developpement/nodejs/oauth2/test/node_modules/passport/lib/passport/middleware/authenticate.js:200:15
at pass (/home/lolostates/Developpement/nodejs/oauth2/test/node_modules/passport/lib/passport/index.js:399:14)
at Passport.transformAuthInfo (/home/lolostates/Developpement/nodejs/oauth2/test/node_modules/passport/lib/passport/index.js:415:5)请求通过curl发送:
curl -H "Authorization: Bearer NoulKM889Aksf60rQONcUJwMuZHI3PDqzeXfkX3Li2BohsxNVsOrd2LLdvJAGZuE168IukUCPbviazhvBjt7VDfLFUMJRIY1fa95kGXQQKzE7etFhocsnYvbLSixbHRmCwXNx5FKj6v83Ci9f9xLqRinEKwaAUIjs03hhq8dCWIp7S0Cbi5jdkxlzwfpZxuShoAZYaFInlf4ymG5oyzQe0WJ2POXOaMarGLO7NkjyIMJXWh7s0Y" http://localhost:3000/api/userinfo我使用passport-http-bearer、oAuth2orize和OAuth2orize示例中提供的所有示例函数。
你能给我解释一下为什么吗?
发布于 2014-03-31 22:55:20
看起来您试图在响应发回后设置响应头。在尝试设置标头之前,请检查以确保未调用res.end() (或类似方法)。
https://stackoverflow.com/questions/22764430
复制相似问题