简体   繁体   English

如何访问谷歌 Oauth2 护照中的个人资料信息?

[英]How can I access profile information in google Oauth2 passport?

So I want the index page to show the name of the user currently logged in in the footer of the index page.所以我希望索引页在索引页的页脚中显示当前登录的用户的名称。
My google login routes我的谷歌登录路线

router.get("/login/google", passport.authenticate('google', { scope:
    [ 'email', 'profile' ] }));
router.get("/login/google/callback", passport.authenticate("google", {
    successRedirect: "/videos",
    failureRedirect: "/login/google/error"
}));
router.get("/login/google/error", (req, res) => {
    res.send("Error in google login")
})

My google Strategy我的谷歌策略

passport.use(new GoogleStrategy({
    clientID: GOOGLE_CLIENT_ID,
    clientSecret: GOOGLE_CLIENT_SECRET,
    callbackURL: "http://localhost:3000/login/google/callback",
    passReqToCallback: true
  },
  function(request, accessToken, refreshToken, profile, done) {
    User.findOrCreate({ googleId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

My footer of the index file我的索引文件页脚

    <footer>
    <% if(!auth){ %>
      <li class="nav-item">
        <a href="/register" class="nav-link active">Register!</a>
        <li class="nav-item">
          <a href="/login" class="nav-link active">Log In</a>
        </li>
      </li>
    <% } else { %>
      <li class="nav-item">
        <a href="#" class="nav-link disabled">Welcome, <%= auth.username %> </a>
      </li>
      <li class="nav-item">
        <a href="/logout" class="nav-link active">Log Out</a>
      </li>
    <% } %>
  <div class="d-flex justify-content-center mt-3">
  <ul class="nav">
    <li class="nav-item">
      <div class="g-ytsubscribe" data-channelid="UCAjHeCmPJ5lDVWw6dL_jQng" data-layout="default" data-count="default"></div>
    </li>
  </ul>
</footer>

My Footer我的页脚
页脚 IMG

I setted user to profile in my google strategy and then idk how it was saved in req.user我在我的谷歌策略中将用户设置为配置文件,然后知道它是如何保存在 req.user 中的
EDIT:编辑:
In other words I saved the profile variable in another variable (req.user).换句话说,我将配置文件变量保存在另一个变量(req.user)中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Passport.js / Google OAuth2 策略 - 如何在登录时使用令牌进行 API 访问 - Passport.js / Google OAuth2 strategy - How to use token on login for API access 如何使用 passport-google-oauth20 获取用户 email - How can I get user email with passport-google-oauth20 如何使用Javascript从Google Api检索服务帐户OAuth2令牌? - How can I retrieve a service account OAuth2 token from Google Api with Javascript? 我如何在Jersey Jersey REST Web服务中使用Google OAuth2 - How can i use google OAuth2 in my Jersey REST Web Service OAuth2 身份验证成功后,如何确保重新发送原始 Google Chat 消息? - How can I ensure re-dispatch of original Google Chat message after OAuth2 authentication succeeds? 通过oauth令牌passport.js访问用户配置文件 - access user profile via oauth tokens passport.js 使用 Javascript 解码 Google Oauth2 访问令牌 - Decode Google Oauth2 Access Token with Javascript 如何注销使用 OAuth2 登录 Google 的应用程序? - How to Logout of an Application Where I Used OAuth2 To Login With Google? 如何使用npm护照在OAuth2网址中订购请求参数 - How to order request parameters in OAuth2 url using npm passport 如何在登录和注册社交之间做出不同的誓言流程? 像谷歌 oauth2.0 使用护照 js - How can i make a different oath flow between login & signup for social? like google oauth2.0 using passport js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM