2015-05-09 6 views
16

एक की परिचयात्मक book (एक अनुप्रयोग का उपयोग प्रमाणीकरण गूगल OpenID द्वारा रणनीति) के अंतिम उदाहरण डेवलप करते समय, के बाद passport-google पैकेज (जो 20 अप्रैल, 2015 को अप्रचलित हो गया है)passport-google-oauth2 पैकेज (Google OAuth 2.0 द्वारा प्रमाणीकरण रणनीति) और its documentation's page और example here पर संकेतों का पालन करने के बाद; मुझे oath2.js मॉड्यूल द्वारा फेंक दिया गया था, जो मेरे Google+ खाते को चुनने के बाद नीचे दी गई त्रुटि मिली, userProfile(accessToken, done) विधि के भीतर this._oauth2.get("https://www.googleapis.com/plus/v1/people/me",...) को ठोस रूप से कॉल किया गया। संबंधित स्रोत कोड और मॉड्यूल निर्भरताएं नीचे दी गई हैं।Node.js "पासपोर्ट-google-OAuth2" उद्धार एक्सप्रेस आवेदन में त्रुटि "उपयोगकर्ता प्रोफ़ाइल को लाने में विफल"

समस्या की जड़ क्या हो सकती है?

ठोस त्रुटि है:

InternalOAuthError: failed to fetch user profile 
    at <...>\web-app\b4\node_modules\passport-google-oauth2\lib\oauth2.js:92:28 
    at passBackControl (<...>\web-app\b4\node_modules\passport-google-oauth2\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:124:9) 
    at IncomingMessage.<anonymous> (<...>\web-app\b4\node_modules\passport-google-oauth2\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:143:7) 
    at IncomingMessage.emit (events.js:129:20) 
    at _stream_readable.js:908:16 
    at process._tickCallback (node.js:355:11) 

संबंधित आवेदन के कोड है:

passport = require('passport'), 
    //... 
    GoogleStrategy = require('passport-google-oauth2').Strategy; // #passport-google-oauth2 
    //... 
    /***** #passport-google-oauth2 vv *****/ 
    passport.use(new GoogleStrategy({ 
    clientID: "a_specific_value", 
    clientSecret: "another_specific_value", 
    callbackURL: "http://127.0.0.1:3000/auth/google/callback", 
    passReqToCallback:true 
    }, 
    function(request, accessToken, refreshToken, profile, done) { 
     profile.identifier=profile.id; 
     return done(null, profile); 
    } 
)); 
    /***** #passport-google-oauth2 ^^ *****/ 
    //... 
    /***** #passport-google-oauth2 vv *****/ 
    app.get('/auth/google', 
    passport.authenticate('google', { successRedirect: '/',scope: 
    [ 'https://www.googleapis.com/auth/userinfo.email']}) 
); 
    app.get('/auth/google/callback', 
    passport.authenticate('google', { 
     successRedirect: '/', 
     failureRedirect: '/' 
    })); 
    /***** #passport-google-oauth2 ^^ *****/  

एप्लिकेशन के पास निम्न निर्भरता है:

 
[email protected] 
├─┬ [email protected] 
│ ├─┬ [email protected] 
│ │ └── [email protected] 
│ └── [email protected] 
├─┬ [email protected] 
│ ├── [email protected] 
│ └── [email protected] 
├─┬ [email protected] 
│ ├── [email protected] 
│ ├─┬ [email protected] 
│ │ └── [email protected] 
│ ├─┬ [email protected] 
│ │ ├── [email protected] 
│ │ ├── [email protected] 
│ │ ├── [email protected] 
│ │ ├── [email protected] 
│ │ └── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├─┬ [email protected] 
│ │ └── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ └─┬ [email protected] 
│ └── [email protected] 
├─┬ [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├─┬ [email protected] 
│ │ └── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├─┬ [email protected] 
│ │ ├── [email protected] 
│ │ └── [email protected] 
│ └── [email protected] 
├─┬ [email protected] 
│ ├── [email protected] 
│ ├─┬ [email protected] 
│ │ └── [email protected] 
│ ├── [email protected] 
│ └─┬ [email protected] 
│ └── [email protected] 
├─┬ [email protected] 
│ └── [email protected] 
├─┬ [email protected] 
│ ├── [email protected] 
│ └── [email protected] 
├─┬ [email protected] 
│ └─┬ [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ └── [email protected] 
├── [email protected] 
├── [email protected] 
└─┬ [email protected] 
    ├── [email protected] 
    ├── [email protected] 
    ├── [email protected] 
    ├─┬ [email protected] 
    │ ├── [email protected] 
    │ └─┬ [email protected] 
    │ └── [email protected] 
    ├─┬ [email protected] 
    │ ├── [email protected] 
    │ ├── [email protected] 
    │ ├── [email protected] 
    │ └── [email protected] 
    ├─┬ [email protected] 
    │ ├── [email protected] 
    │ ├── [email protected] 
    │ └── [email protected] 
    ├── [email protected] 
    ├── [email protected] 
    ├── [email protected] 
    ├── [email protected] 
    ├── [email protected] 
    └── [email protected] 

उत्तर

49

मैं सिर्फ सौभाग्य से एक पायापर इसी तरह की समस्याjaredhanson/passport-google-oauth, जो मुझे Google's project console पर जाने के लिए और बस Google+ API, किया गया था जो "बंद" सक्षम विचार दिया (ओह मुझे !!, अपनी पहली आवेदन की अनुभवहीन डेवलपर गूगल + पर आधारित)। वह समस्या की जड़ थी। मैंने फिर कोशिश की और oauth2 प्रोफाइल को सही तरीके से प्राप्त करना शुरू कर दिया।

+1

वास्तव में है कि:

passport.authenticate('google', { successRedirect: '/',scope: ['email'] })); 

तुम भी profile scope प्राप्त कर सकते हैं:

passport.authenticate('google', { successRedirect: '/',scope: [ 'https://www.googleapis.com/auth/userinfo.email']}) ); 

इसके बजाय, हम इस एक का उपयोग करना चाहिए यह मेरे लिए भी था, धन्यवाद! // www.googleapis.com/प्रमाणन/userinfo.profile' और 'https: // www.googleapis.com/प्रमाणन/userinfo.email'' profile' और 'ईमेल करने के लिए बदल – Nocturno

+1

मैं भी पदावनत स्कोप' https था क्रमशः। – Samin

+0

वाह धन्यवाद इस पर इतना समय बिताया। वे वास्तव में किसी तरह की त्रुटि वापस करना चाहिए! मेरे लिए कॉलबैक –

4

scope प्रयोग कर रहे हैं अब पदावनत किया गया है:

passport.authenticate('google', { successRedirect: '/',scope: 
    [ 'email', 'profile' ] 
})); 
+0

मुझे गितूब ओथ के साथ एक ही समस्या हो रही है। कोई विचार क्या गुम है? – Sandeep

संबंधित मुद्दे