如何将Facebook登录名添加到Node.js,Express,Swagger?

时间:2018-08-06 08:00:18

标签: node.js facebook express swagger

全部!我有Node.js,Express和Swagger(使用swagger-express-mw和swagger-tools / middleware / swagger-ui)。 我知道如何实现OAuth Facebook登录到Node.js和Express的方法,但是急于停止逻辑。 例如,此逻辑有效:

app.get('/auth/facebook',
passport.authenticate('facebook'));

app.get('/auth/facebook/callback',
passport.authenticate('facebook', { failureRedirect: '/login' }),
function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
});
    passport.use(new FacebookStrategy({
        clientID: process.env.FB_ID,
        clientSecret: process.env.FB_SECRET,
        callbackURL: 'http://localhost:5100/api/auth/facebook/callback'
    },
    function(accessToken, refreshToken, profile, cb) {
        console.log('accessToken, refreshToken, profile, cb');
        console.log(accessToken, refreshToken, profile, cb);
        // User.findOrCreate({ facebookId: profile.id }, function (err, user) {
        //     return cb(err, user);
        // });
        // return profile
    }
));

但是如果我使用Swagger实现,那么在“ / login / facebook”之后我什么也没做:

  /auth/facebook/callback:
x-swagger-router-controller: Authorization
get:
  operationId: facebookCallback
  summary: Facebook login
  tags:
    - facebook
  responses:
    "200":
      description: Successful response
      schema:
        $ref: "#/definitions/Response"
/login/facebook:
  x-swagger-router-controller: Authorization
  get:
    operationId: facebook
    summary: Facebook login
    tags:
      - facebook
    responses:
      "200":
        description: Successful response
        schema:
          $ref: "#/definitions/Response"


function facebook(req, res, next) {
  console.log('Stopped here');
  passport.authenticate('facebook');
}
function facebookCallback(req, res, next) {
  passport.authenticate('facebook', { failureRedirect: '/login' }),
    function(req, res) {
    console.log('Callback wasn\'t called');
        // Successful authentication, redirect home.
        res.redirect('/');
    }
}

所以,我不明白为什么看不到Facebook登录页面?

0 个答案:

没有答案