简体   繁体   English

Passport facebook 令牌 Oauth2 在令牌良好时抛出内部服务器错误,但在令牌错误时工作正常

[英]Passport facebook token Oauth2 throwing Internal Server Errors when the token is good but works fine when token is wrong

What am I missing here?我在这里缺少什么? I've been through all the threads here and googled it for a while:我已经浏览了这里的所有线程并用谷歌搜索了一段时间:

  • Whitelisted my machine's IP under the apps advanced settings.在应用程序高级设置下将我机器的 IP 列入白名单。
  • Double-checked the token and when it's expired I can see that error on the console.仔细检查令牌,当它过期时,我可以在控制台上看到该错误。
  • Double checked client + secret + origins in the app在应用程序中仔细检查客户端 + 机密 + 来源
  • Tried things with a google oauth token and I get 'unauthorized' as intended.使用 google oauth 令牌尝试了一些事情,我按预期获得了“未经授权”。

But when all is good and I send a request with that good token either from Postman or from my frontend I get Internal Server Error telling me User is not defined at that line.但是,当一切顺利并且我从 Postman 或我的前端发送带有该好的令牌的请求时,我收到内部服务器错误,告诉我用户未在该行定义。 What am I missing?我错过了什么?

Route code:路线代码:

app.get(
  '/user',
  passport.authenticate('facebook-token', { session: false }),
  function(req, res) {
    res.send('SUCCESS');
  }
);

All other code without imports:没有导入的所有其他代码:

app.use(cors());
app.use(express.json());
app.use(helmet());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(passport.initialize());
passport.use(
  new FacebookTokenStrategy(
    {
      clientID: config.get('facebook.clientID'),
      clientSecret: config.get('facebook.clientSecret')
    },
    function(accessToken, refreshToken, profile, done) {
      User.findOrCreate({ facebookId: profile.id }, function(error, user) {
        return done(error, user);
      });
    }
  )
);

and I'm importing the npm package exactly as in the docs:我正在完全按照文档中的方式导入 npm 包:

const FacebookTokenStrategy = require('passport-facebook-token');

I'm all out of ideas on this one.我对这个完全没有想法。

app.use(cors());
app.use(express.json());
app.use(helmet());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(passport.initialize());
passport.use(
  new FacebookTokenStrategy(
    {
      clientID: config.get('facebook.clientID'),
      clientSecret: config.get('facebook.clientSecret')
    },
    function(accessToken, refreshToken, profile, done) {
      return done(null, profile);
    }
  )
);

Try this尝试这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 koa 护照 oauth2 将令牌保存到状态 - koa passport oauth2 save token to state 使用OAuth2 API时如何存储令牌 - How to store token when using OAuth2 API Passport-facebook-token返回InternalOAuthError:验证令牌时无法获取用户个人资料 - passport-facebook-token returns InternalOAuthError: Failed to fetch user profile when verifying the token 护照获取刷新令牌 OAuth - Passport Get Refresh Token OAuth 使用 Node.js 和 express.js 实现护照-facebook-token 时出现 500 内部服务器错误 - 500 Internal Server Error in passport-facebook-token implementation using Node.js and express.js Nestjs 护照-facebook 无效的 OAuth 访问令牌 - Nestjs passport-facebook Invalid OAuth access token Node + Express应用程序中的Passport + Google Token不断向邮递员抛出“未经授权”的尝试,令牌很好,并经过手动验证 - Passport + Google Token in Node + Express app keeps throwing 'Unauthorized' to attempts from Postman, token is good and manually verified 无效的oauth2令牌请求 - invalid oauth2 token request 在 Heroku 上实时部署时,passport google oauth2 会导致“内部服务器错误” - passport google oauth2 causes “internal server error” when deployed live on Heroku 使用Passport-google-oauth的OAuth2:GET请求中没有正文,但我仍然收到一些令牌 - OAuth2 using passport-google-oauth: there is no body in GET request but I still recieve some token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM