我正在尝试为安卓客户端实现google oAuth2。我发送空 GET请求谷歌登录,并收到一些令牌。我不明白为什么会这样。我使用了我的web客户端id和来自开发者控制台的秘密。
这是我的代码:
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
passport.use(new GoogleStrategy({
clientID: 'MY CLIENT ID',
clientSecret: 'MY SECRET',
callbackURL: "http://mysite.io/account/googleLogin/callback"
},
function(accessToken, refreshToken, profile, cb) {
console.log("collection findOrCreate");
console.log("accessToken " + accessToken);
console.log("createIndex" + profile.id);
}
app.get('/googleLogin',
passport.authenticate('google', { scope: ['profile'] }));
app.get('/googleLogin/callback',
passport.authenticate('google', { failureRedirect: '/login' }),
function(req, res) {
// Successful authentication, redirect home.
console.log("Google Login Success!");
res.redirect('/');
});日志:
accessToken ya29.tAI7uCiN-JFKWflq4Wm6xbyQjk1S-qdlB6Ks6GTHnNzzr0N_jz8rUVPZLVlvi4aIkF6SGvw
createIndex 102114909694672049994当我和身体一起发送时,效果是一样的。
GET http://mysite.io/account/googleLogin/
{ "idToken": "sometoken" }发布于 2016-03-30 19:57:46
我找到了不同的方法。第一部分是:
router.get('/googleLogin', passport.authenticate('google', { scope : ['profile', 'email'] }));将用户重定向到google授权页面,该页面成功后称为回调方法。这不是我所需要的,因为我已经在Android端有了一个令牌。
对于Android客户端,一种方法是手动检查google tokenId是否有效,向gooogle发送请求。从官方来源实现这部分解决了我的问题:https://developers.google.com/identity/sign-in/android/backend-auth#verify-the-integrity-of-the-id-token
https://stackoverflow.com/questions/36289524
复制相似问题