如何访问 google Oauth2 护照中的个人资料信息?
How can I access profile information in google Oauth2 passport?
所以我希望索引页在索引页的页脚中显示当前登录的用户名。
我的google登录路径
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")
})
我的google策略
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);
});
}
));
我的索引文件的页脚
<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>
我的页脚
我在我的 google 策略中设置了用户配置文件,然后我知道它是如何保存在 req.user
中的
编辑:
换句话说,我将配置文件变量保存在另一个变量中 (req.user).
所以我希望索引页在索引页的页脚中显示当前登录的用户名。
我的google登录路径
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")
})
我的google策略
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);
});
}
));
我的索引文件的页脚
<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>
我的页脚
我在我的 google 策略中设置了用户配置文件,然后我知道它是如何保存在 req.user
中的
编辑:
换句话说,我将配置文件变量保存在另一个变量中 (req.user).