Nestjs passport-facebook Invalid OAuth access token

518 views Asked by At

I'm implementing passport-facebook in my NestJS application. I found many examples and problems with different solutions, and I was trying to implement it in different ways but still no luck. Here is my strategy:

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);
    },),);}}

And controller handler:

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

Im pretty sure I use correct clientID and clientSecret. On facebook developers tool I generate token like this: token

So I use this token to call http://127.0.0.1:3000/auth/facebook?session_token=EAAgSTU1....WpHZAPgZDZD and receive the following error:

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

Where is my mistake? Many thanks!

1

There are 1 answers

0
Artem On

The problem was wrong query variable name. It must be access_token