2014-10-06 2 views
11

I 여권 구글-의 OAuth를 사용하여 다음 노드 코드 ...여권 - 구글의 OAuth 콜백

app.get('/auth/google', passport.authenticate('google', { scope : ['profile', 'email'] })); 

app.get('/auth/google/callback', function(req,res) { 
    console.log("callback"); 
    passport.authenticate('google', { 
       successRedirect : '/signin', 
       failureRedirect : '/signin' 
    }); 
}); 

하고 ...이

문제가
passport.serializeUser(function(user, done) { 
    console.log("ser"); 
    done(null, user.id); 
}); 

passport.deserializeUser(function(id, done) { 
    console.log("des"); 
    User.findById(id, function(err, user) { 
     done(err, user); 
    }); 
}); 

passport.use(new GoogleStrategy({ 

    clientID  : 'id', 
    clientSecret : 'key', 
    callbackURL  : 'http://host/auth/google/callback', 
}, 
function(token, rtoken, profile, done) { 
    console.log("proc"); 
    console.log(profile); 
    done(null, profile); 
})); 

, 콜백을 작동하지 않음 호출되고 있지만 아무것도 발생합니다. 처리 기능은 절대로 안타깝습니다. 콜백은 시간 초과됩니다. 내가 잘못한 어떤 생각?

+0

'console.log ("callback"); – xShirase

+0

또한/signin 경로는 어떻게 생겼습니까? 또한 콜백은 get 또는 post 여야합니다. 나는 그것이 보통 게시물이라고 생각한다. –

+0

문제가 GoogleStrategy에 있습니다. 사용해보십시오. var GoogleStrategy = require ('passport-google-oauth'). OAuth2Strategy; – Dyrk

답변

1

난 그냥 여권 - 구글 - OAuth를 패키지는 다음 내보내는 것을 발견 : 의미

exports.Strategy = 
exports.OAuthStrategy = OAuthStrategy; 
exports.OAuth2Strategy = OAuth2Strategy; 

, "기본"(. 즉 전략) 전혀 OAuth2를하지 않는 것을 ... 그래서 더 나은 명시 적으로 OAuth2Strategy를 사용하십시오. 그것은 나를 위해 일했다. 이게 문제인지 알기 위해 몇 시간 만에 ...