小编eic*_*han的帖子

如何在 Node-Express / Vue Web 应用程序中管理 OAuth?

我对如何在我的应用程序中管理 OAuth 流程感到有些困惑。我可以让它工作,但我不确定最佳实践,并希望找到一些关于该主题的好文章/教程/文档。

我的应用程序结构如下:

  • 一个 Vue 前端,通过 axios 向后端发出 HTTP 请求
  • 使用 Passport.js 的 Node.js / Express 后端,允许本地、谷歌和 Facebook 策略

Passport 是这样配置的:

passport.use(
    new GoogleStrategy(
        {
            clientID: process.env.GOOGLE_CLIENT_ID,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET,
            callbackURL: '/api/login/google/callback'
        },
        async (accesToken, refreshToken, profile, done) => {
            try {
                let user = await User.findOne({ googleId: profile.id });
                if (user) {
                    if (
                        user.email != profile.emails[0].value ||
                        user.pic != profile.photos[0].value
                    ) {
                        user.email = profile.emails[0].value;
                        user.pic = profile.photos[0].value;
                        user.save();
                    }
                    return done(null, user);
                } else {
                    user = …
Run Code Online (Sandbox Code Playgroud)

oauth node.js express vue.js passport.js

6
推荐指数
1
解决办法
367
查看次数

标签 统计

express ×1

node.js ×1

oauth ×1

passport.js ×1

vue.js ×1