我在我的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)
}我非常确定我使用了正确的clientID和clientSecret。在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"}}' }我的错误在哪里?非常感谢!
发布于 2020-09-28 18:49:39
问题是查询变量名错误。它必须是access_token
https://stackoverflow.com/questions/64097740
复制相似问题