Trong khi phát triển ví dụ cuối cùng của giới thiệu book (express.js ứng dụng sử dụng chiến lược xác thực của Google OpenID), sau thay thế gói passport-google
(đã lỗi thời vào ngày 20 tháng 4 năm 2015) với gói passport-google-oauth2
(chiến lược xác thực của Google OAuth 2.0) và đã làm theo các chỉ dẫn tại its documentation's page và example here; Tôi gặp lỗi bên dưới sau khi chọn tài khoản Google+ của mình, được ném bởi mô-đun oath2.js
, cụ thể gọi this._oauth2.get("https://www.googleapis.com/plus/v1/people/me",...)
trong phương thức userProfile(accessToken, done)
. Mã nguồn có liên quan và phụ thuộc mô-đun bên dưới.Node.js "hộ chiếu-google-oauth2" cung cấp lỗi "không tìm nạp hồ sơ người dùng" trong ứng dụng Express
Điều gì có thể là gốc của sự cố?
Các lỗi cụ thể là:
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)
mã ứng dụng có liên quan là:
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 ^^ *****/
Ứng dụng này có sự phụ thuộc như sau:
[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]
Đó chính xác những gì nó đã cho tôi quá, cảm ơn! – Nocturno
Tôi cũng đã thay đổi các phạm vi không được chấp nhận 'https: // www.googleapis.com/auth/userinfo.profile' và' https: // www.googleapis.com/auth/userinfo.email' thành 'hồ sơ' và' email 'tương ứng. – Samin
wow cảm ơn đã dành rất nhiều thời gian cho việc này. họ thực sự nên trả lại một số loại lỗi! cho tôi gọi lại sẽ treo –