简介 我正在使用 google 的开放式身份验证,以便用户使用 google 身份验证登录。对 node js使用passport-google-oauth2包。
代码运行良好,除了我一直在发送状态变量但获得不同状态值的一件事。首先我认为这可能是一些配置问题。从最后一天阅读状态参数开始,我想我可能做错了配置。
网络框架:Koa Js
代码验证
passport.use(new GoogleStrategy({
clientID: 'xxxxxxxxxxx.apps.googleusercontent.com',
clientSecret: 'xxxxxxxxxxxxxxxxxxxxxx',
callbackURL: 'http://localhost:5000/auth/callback/google',
passReqToCallback: true,
response_type:'token',
scope: "openid profile email",
state: base64url(JSON.stringify({blah: 'test'})),
accessType: 'offline'
},
function(request, accessToken, refreshToken, profile, done) {
if(accessToken){
console.log('-------request--------??', request);
console.log('-------accessToken--------??', accessToken);
console.log('-------refreshToken--------??', refreshToken);
console.log('-------profile--------??', profile);
console.log('-------authenticated-------');
done(null, user);
}
else{
console.log('-------not authenticated-------');
done(null, false);
}
}
));
在重定向中,我得到了查询字符串中的所有参数,还有具有不同值的状态变量。
示例查询字符串
{
state: 'T3Lx3XvvSlsGitbNqlCM8CEB',
code: '4/AABGuKCh3Sp0kv2eWSbYsUEAT4iXA2k9u7o2X_ICw0wchiIq38MofOuTmx_yGQSXAFn7iAq9meZXUKRh0qVOAv0',
authuser: '0',
session_state: 'af3af7767c5501d163fa847225b863a9982d76ef..1c9b',
prompt: 'none'
}
如果有人对此问题有任何想法,请提供帮助。谢谢你的时间。