【发布时间】: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)
}
我很确定我使用了正确的 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"}}' }
我的错误在哪里?非常感谢!
【问题讨论】:
标签: node.js facebook-graph-api passport.js nestjs passport-facebook