【问题标题】:Nestjs passport-facebook Invalid OAuth access tokenNestjs passport-facebook 无效的 OAuth 访问令牌
【发布时间】:2021-01-13 18:34:42
【问题描述】:

我在我的 NestJS 应用程序中实现 passport-facebook。我发现了许多不同解决方案的示例和问题,我试图以不同的方式实现它,但仍然没有运气。 这是我的策略:

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

    @Injectable()
    export class FacebookStrategy {
      constructor() {
        this.init();
      }
      init() {
        use(
          new FacebookTokenStrategy(
            {
              clientID: '...',
              clientSecret: '...',
              fbGraphVersion: 'v8.0',
              profileFields: ['id', 'emails']
            },
            async (
              accessToken: string,
              refreshToken: string,
              profile: any,
              done: any,
            ) => {
              console.log('facebook profile:', profile);
              return done(null, null);
    },),);}}

和控制器处理程序:

@UseGuards(AuthGuard('facebook-token'))
  @Get('facebook')
  async getTokenAfterFacebookSignIn(@Req() req) {
    console.log(req)
}

我很确定我使用了正确的 clientIDclientSecret。在 facebook 开发人员工具上,我生成这样的令牌:

所以我使用这个令牌调用http://127.0.0.1:3000/auth/facebook?session_token=EAAgSTU1....WpHZAPgZDZD 并收到以下错误:

oauthError: { statusCode: 400, data: '{"error":{"message":"Invalid OAuth access token.","type":"OAuthException","code":190,"fbtrace_id":"AJqucuXGs8DnoYzT3i5cO7p"}}' }

我的错误在哪里?非常感谢!

【问题讨论】:

    标签: node.js facebook-graph-api passport.js nestjs passport-facebook


    【解决方案1】:

    问题是查询变量名错误。必须是access_token

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-28
      • 1970-01-01
      • 2012-06-22
      • 2018-09-24
      • 2015-04-27
      • 1970-01-01
      • 2019-07-27
      • 2019-09-14
      相关资源
      最近更新 更多