gpt4 book ai didi

mysql - REST API、OAuth2 和身份验证错误

转载 作者:行者123 更新时间:2023-11-30 00:27:24 25 4
gpt4 key购买 nike

首先感谢您的回复。我尝试使用 nodeJS 制作 REST API,并且我认为 oAuth2 是根据我的系统对用户进行身份验证的最佳方式。

用户存储在 LDAP 中,API key 将保存在 MySQL 引擎上。客户帐户代码也将存储在 MySQL 中。所有过程都正常,用户经过身份验证,API token 已保存在 MySQL 中,但是当我尝试使用此 token 时, 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 示例中提供的所有示例函数。

你能解释一下为什么吗?

最佳答案

您似乎试图在响应发回后设置响应 header 。在尝试设置 header 之前,请检查并确保您没有调用 res.end() (或类似的方法)。

关于mysql - REST API、OAuth2 和身份验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22764430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com