如何提供个人资料信息,以便Passport.js可以使用它?

时间:2014-02-19 19:22:42

标签: php node.js oauth passport.js

我正在尝试使用oauth2-server-php为网站实现自定义OAuth2提供程序,以使用Passport对node.js客户端进行身份验证。

已实施的端点(例如授权,令牌)与this oauth2-server-php tutorial中描述的完全相同。

在我的node.js应用程序中,我使用Passport的oauth2策略,使用与此类似的配置(来自护照文档):

passport.use(new OAuth2Strategy({
    authorizationURL: 'https://www.example.com/oauth2/authorize',
    tokenURL: 'https://www.example.com/oauth2/token',
    clientID: EXAMPLE_CLIENT_ID,
    clientSecret: EXAMPLE_CLIENT_SECRET,
    callbackURL: "http://localhost:3000/auth/example/callback"
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ exampleId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

如您所见,它使用function(accessToken, refreshToken, profile, done)处理收到的信息。

我的问题是:我如何提供(在我的自定义oauth2提供程序中)profile参数,以便Passport可以访问它? 正是来自哪里?

1 个答案:

答案 0 :(得分:0)

您需要像Facebook策略那样实施UserProfile功能:

https://github.com/jaredhanson/passport-facebook/blob/master/lib/strategy.js#L137