使用护照处理Google针对移动和网络的oAuth流程?

时间:2019-04-24 20:45:25

标签: oauth passport.js

所以我已经使用护照实现了Google oAuth流,这是我现在的代码:


const strategyCallback = async (accessToken, refreshToken, profile, cb) => {
  try {
    const user = await models.user.findOrCreate({
      where: {
        googleId: profile.id,
        firstName: profile.name.givenName,
        lastName: profile.name.familyName,
        email: profile.emails[0].value,
        username: profile.emails[0].value.split('@')[0],
        profilePictureUrl: profile.photos[0].value
      }
    });
    return cb(null, user);
  } catch (e) {
    return cb(e, false);
  }
};

passport.use(
  new GoogleStrategy(
    {
      clientID: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_SECRET,
      callbackURL: process.env.GOOGLE_CALLBACK
    },
    strategyCallback
  )
);

const authenticate = passport.authenticate('google', {
  scope: ['profile', 'email']
});

const authenticateCallback = passport.authenticate('google', {
  session: false,
  failureRedirect: '/login'
});

身份验证之后,我正在签名并发送JWT供用户用于受保护的路由。

现在,这一切都适用于网络,但Android团队将使用我的API。他们希望改用应用程序内部的同意书,然后将其访问令牌发送回后端。我们本质上是想获取此令牌并进行比较以验证用户身份。我有两个问题。

使用护照可以吗?我们在哪里拦截在策略回调中发送回的访问令牌?

还有两个,我们没有在数据库中存储accessToken。那么到底怎么做呢?

0 个答案:

没有答案