代码之家  ›  专栏  ›  技术社区  ›  Abhi Patoliya

我正在使用Google OAuth进行身份验证。如何获取用户的详细信息

  •  -1
  • Abhi Patoliya  · 技术社区  · 2 年前

    我正在使用谷歌护照进行身份验证。
    但现在我想要一些用户的额外细节,比如个人资料图片和性别。
    那么我该如何获取用户的个人资料图像和性别呢。

    真的很感激帮助。

    exports.googlePassport = catchAsync(async (req, res, next) => {
        passport.use(new GoogleStrategy({
            clientID: process.env.GOOGLE_CLIENT_ID,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET,
            callbackURL: "http://localhost:8001/api/v1/user/google/callback",
            scope: ["profile", "email"]
        }, async (profile) => {
            const newUser = {
                googleId: profile.id,
                firstname: profile.name.givenName,
                lastname: profile.name.familyName,
                email: profile.emails[0].value
            };
        }));
    })
    
    2 回复  |  直到 2 年前
        1
  •  2
  •   Deep Kaswala    2 年前

    个人资料图像可以提取,但只有当用户在其谷歌个人资料中允许每个人都可以访问性别时,才能提取性别。

    exports.googlePassport = catchAsync(async (req, res, next) => {
    passport.use(new GoogleStrategy({
        clientID: process.env.GOOGLE_CLIENT_ID,
        clientSecret: process.env.GOOGLE_CLIENT_SECRET,
        callbackURL: "http://localhost:8001/api/v1/user/google/callback",
        scope: ["profile", "email"]
    }, async (profile) => {
        const newUser = {
            googleId: profile.id,
            firstname: profile.name.givenName,
            lastname: profile.name.familyName,
            email: profile.emails[0].value,
            profileImage: profile.photos[0].value,
            gender: profile.gender
        };
    }));
    

    })

        2
  •  -2
  •   Kotagiri Vinod    2 年前

    您可以以以下身份访问用户: const userInfo=请求用户_json

    推荐文章