Preidx Seed Oauth 回调报错 404

lihongxun945 2017-03-17 02:02:53
问题:

登录之后跳转回应用的时候报错:

http://localhost:5000/callback?code=###,

{"message":"Not Found","error":{"status":404}}

服务器端报这个错误:

Error at C:\codes\predix-seed\node_modules\passport-oauth\lib\passport-oauth\strategies\oauth2.js:125:38 at C:\codes\predix-seed\node_modules\oauth\lib\oauth2.js:177:18 at ClientRequest. (C:\codes\predix-seed\node_modules\oauth\lib\oauth2.js:148:5) at emitOne (events.js:96:13) at ClientRequest.emit (events.js:188:7) at TLSSocket.socketErrorListener (_http_client.js:309:9) at emitOne (events.js:96:13) at TLSSocket.emit (events.js:188:7) at emitErrorNT (net.js:1281:8) at _combinedTickCallback (internal/process/next_tick.js:74:11)

回答:
在 passport中为了能正确处理 code,nodejs中会有一个回调url的定义。
在predix-seed中已经写好了这部分代码:
https://github.com/PredixDev/predix-seed/blob/develop/server/app.js#L107

1. //callback route redirects to secure route after login
2. app.get('/callback', passport.authenticate('predix', {
3. failureRedirect: '/'
4. }), function(req, res) {
5. console.log('Redirecting to secure route...');
6. res.redirect('/');
7. });

localConfig.json 文件中定义了定义了需要配置的 credential:

{
"development": {
"note": "Out of the box, the predix-seed app uses mock data, so these values are not required. Set these values for connecting to real Predix services.",
"clientId": "{UAA Client ID created}",
"uaaURL": "{The UAA URI end point to get auth token }",
"base64ClientCredential": "{Get clientID:clientSecret then base64 encode and place it here}",
"appURL": "http://localhost:5000",
"timeseriesURL": "{Time Series URL from VCAPS}",
"timeseriesZoneId": "{The Zone ID for the Timeseries Service Created}",
"assetURL": "{Asset URL from VCAPS}",
"assetZoneId": "{The Zone ID for the Asset Service Created}",
"windServiceURL": "{URL of the microservice <your-name>-winddata-timeseries-service}, e.g. https://your-name-winddata-timeseries-service.run.asw-usw02-pr.predix.io"
}
}

这两部分都正确配置之后,你的应用应该就能正确处理 ?code=xxx
...全文
86 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tangyiguo 2017-04-11
  • 打赏
  • 举报
回复
感谢分享!希望更多的开发者可以分享自己的成功经验。
hytrew 2017-03-17
  • 打赏
  • 举报
回复
我也遇到了这个问题,终于解决了

163

社区成员

发帖
与我相关
我的任务
社区描述
GE的Predix平台整合云计算可扩展性、大数据管理和高级分析技术来助力新一代的数字化企业。结合GE自己作为全球工业界领导者的经验,Predix云平台为开发高级工业应用程序提供可连接性、安全和高性能。
云计算大数据 技术论坛(原bbs)
社区管理员
  • GE Predix工业互联网开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧