我正在我的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"}}' }
我的错误在哪里?非常感谢!
答案 0 :(得分:0)
问题是查询变量名称错误。它必须是access_token