我正在使用passport.js来验证用户身份。我希望能够传递从用户收集的用户名,该用户名将在验证过程结束时通过,这样我就可以在创建用户时存储用户名(如果它尚不存在)。我试过这个:
app.get("/auth/google", function(request, response)
{
console.log(request.query.username);
passport.authenticate("google",
{
scope:
[
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/userinfo.email"
]
})(request, response);
});
app.get("/auth/google/callback", function(request, response)
{
console.log(request.query.username);
passport.authenticate("google",
{
successRedirect: "/",
failureRedirect: "htm/error"
})(request, response);
});
对/ auth / google的调用打印用户名,但回调打印未定义。即使我可以获得回调用户名,我仍然不确定如何获得谷歌策略。那么我是否必须制定自己的策略才能使其发挥作用?
答案 0 :(得分:9)
您可以将州对象传递给passport.authenticate,如下所示:
passport.authenticate("google",
{
scope:
[
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/userinfo.email"
],
state: request.query.username
})(request, response);
您可以通过 req.query.state 访问该州。
用户名应该是字符串,而不是对象。如果要在状态中存储对象,请先调用 JSON.stringify 并在回调中解析它。
答案 1 :(得分:2)
对于使用OpenID的任何人来说,req.query似乎被OpenId查询参数覆盖,因此不能直接传递。但是,您可以将变量附加到req.session。
Dim networkInfo
Dim nameVal
Dim infoStr
Dim insult
Set networkInfo = CreateObject("WScript.NetWork")
nameVal=1
infoStr = networkInfo.UserName & vbCr & vbLf
if InStr(1, networkInfo, "a") > 0 Then
nameVal = nameVal + 1
Elseif InStr(1, networkInfo, "b") > 0 Then
nameVal = nameVal + 2
Elseif InStr(1, networkInfo, "c") > 0 Then
nameVal = nameVal + 3
Elseif InStr(1, networkInfo, "d") > 0 Then
nameVal = nameVal + 4
Elseif InStr(1, networkInfo, "e") > 0 Then
nameVal = nameVal + 5
Elseif InStr(1, networkInfo, "f") > 0 Then
nameVal = nameVal + 6
Elseif InStr(1, networkInfo, "g") > 0 Then
nameVal = nameVal + 7
Elseif InStr(1, networkInfo, "h") > 0 Then
nameVal = nameVal + 8
Elseif InStr(1, networkInfo, "i") > 0 Then
nameVal = nameVal + 9
Elseif InStr(1, networkInfo, "j") > 0 Then
nameVal = nameVal + 10
Elseif InStr(1, networkInfo, "k") > 0 Then
nameVal = nameVal + 11
Elseif InStr(1, networkInfo, "l") > 0 Then
nameVal = nameVal + 12
Elseif InStr(1, networkInfo, "m") > 0 Then
nameVal = nameVal + 13
Elseif InStr(1, networkInfo, "n") > 0 Then
nameVal = nameVal + 14
Elseif InStr(1, networkInfo, "o") > 0 Then
nameVal = nameVal + 15
Elseif InStr(1, networkInfo, "p") > 0 Then
nameVal = nameVal + 16
Elseif InStr(1, networkInfo, "q") > 0 Then
nameVal = nameVal + 17
Elseif InStr(1, networkInfo, "r") > 0 Then
nameVal = nameVal + 18
Elseif InStr(1, networkInfo, "s") > 0 Then
nameVal = nameVal + 19
Elseif InStr(1, networkInfo, "t") > 0 Then
nameVal = nameVal + 20
Elseif InStr(1, networkInfo, "u") > 0 Then
nameVal = nameVal + 21
Elseif InStr(1, networkInfo, "v") > 0 Then
nameVal = nameVal + 22
Elseif InStr(1, networkInfo, "w") > 0 Then
nameVal = nameVal + 23
Elseif InStr(1, networkInfo, "x") > 0 Then
nameVal = nameVal + 24
Elseif InStr(1, networkInfo, "y") > 0 Then
nameVal = nameVal + 25
Elseif InStr(1, networkInfo, "z") > 0 Then
nameVal = nameVal + 26
Else MsgBox ("")
End If
If nameVal < 5 Then
insult = ("")
Elseif nameVal > 5 Then
insult = ("")
Elseif nameVal > 10 Then
insult = ("")
Elseif nameVal > 20 Then
insult = ("")
Elseif nameVal > 30 Then
insult = ("")
Elseif nameVal > 40 Then
insult = ("")
Elseif nameVal > 50 Then
insult = ("")
Elseif nameVal > 60 Then
insult = ("")
Elseif nameVal > 70 Then
insult = ("")
Elseif nameVal > 80 Then
insult = ("")
Elseif nameVal > 90 Then
insult = ("")
Elseif nameVal > 100 Then
insult = ("")
Elseif nameVal > 110 Then
insult = ("")
Elseif nameVal > 120 Then
insult = ("")
Elseif nameVal > 130 Then
insult = (".")
Elseif nameVal > 140 Then
insult = ("")
Elseif nameVal > 150 Then
insult = ("")
Elseif nameVal > 160 Then
insult = ("")
Elseif nameVal > 170 Then
insult = ("")
Elseif nameVal > 180 Then
insult = ("")
Elseif nameVal > 190 Then
insult = ("")
Elseif nameVal > 200 Then
insult = ("")
Elseif nameVal > 210 Then
insult = ("")
Elseif nameVal > 220 Then
insult = ("")
Elseif nameVal > 230 Then
insult = ("")
Elseif nameVal > 240 Then
insult = ("")
Elseif nameVal > 250 Then
insult = ("")
Elseif nameVal > 260 Then
insult = ("")
Elseif nameVal > 270 Then
insult = ("")
Elseif nameVal > 280 Then
insult = ("")
Elseif nameVal > 290 Then
insult = ("")
Elseif nameVal > 300 Then
insult = ("")
Elseif nameVal > 310 Then
insult = ("")
Elseif nameVal > 320 Then
insult = ("")
Elseif nameVal > 330 Then
insult = ("")
Elseif nameVal > 340 Then
insult = ("")
Elseif nameVal > 350 Then
insult = (".")
Elseif nameVal > 360 Then
insult = ("")
Elseif nameVal > 370 Then
insult = ("")
Elseif nameVal > 380 Then
insult = ("")
Elseif nameVal > 390 Then
insult = ("")
Elseif nameVal > 400 Then
insult = ("")
Elseif nameVal > 410 Then
insult = ("")
Elseif nameVal > 420 Then
insult = ("")
Elseif nameVal = 420 Then
insult = ("")
Elseif nameVal > 430 Then
insult = ("")
Elseif nameVal > 440 Then
insult = ("")
Elseif nameVal > 450 Then
insult = ("")
Elseif nameVal > 460 Then
insult = ("")
Elseif nameVal > 470 Then
insult = ("")
Elseif nameVal > 480 Then
insult = ("")
Elseif nameVal > 490 Then
insult = ("")
Elseif nameVal > 500 Then
insult = ("")
Elseif nameVal > 510 Then
insult = ("")
Elseif nameVal > 520 Then
insult = ("")
Elseif nameVal > 530 Then
insult = ("")
End If
MsgBox infoStr & insult
并且不要忘记在策略选项中包含passReqToCallback标志:
router.get('/auth/social', (req, res, next) => {
req.session.foo = req.query.foo;
next();
}, passport.authenticate('social'));