Node.js";passport-google-oauth2“;“交付”;无法获取用户配置文件";Express应用程序中的错误
在开发a的介绍性应用程序的最后一个示例(使用Google OpenID的身份验证策略的应用程序)时,将Node.js";passport-google-oauth2“;“交付”;无法获取用户配置文件";Express应用程序中的错误,node.js,express.js,express,google-oauth,Node.js,Express.js,Express,Google Oauth,在开发a的介绍性应用程序的最后一个示例(使用Google OpenID的身份验证策略的应用程序)时,将passport Google包(于2015年4月20日过时)替换为passport-Google-oauth2包(Google OAuth 2.0的身份验证策略)并已遵循了和的指示;在选择我的Google+帐户后,我得到了下面的错误,这是由oath2.js模块抛出的,具体地说是调用thishttps://www.googleapis.com/plus/v1/people/me“,…)在user
passport Google
包(于2015年4月20日过时)替换为passport-Google-oauth2
包(Google OAuth 2.0的身份验证策略)并已遵循了和的指示;在选择我的Google+帐户后,我得到了下面的错误,这是由oath2.js
模块抛出的,具体地说是调用thishttps://www.googleapis.com/plus/v1/people/me“,…)
在userProfile(accessToken,done)
方法中。下面是相关的源代码和模块依赖项
问题的根源是什么
具体错误是:
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)
应用程序具有以下依赖项:
b4@0.0.1
├─┬ connect-redis@1.4.7
│ ├─┬ debug@2.1.3
│ │ └── ms@0.7.0
│ └── redis@0.10.3
├─┬ cookie-parser@1.3.4
│ ├── cookie@0.1.2
│ └── cookie-signature@1.0.6
├─┬ express@3.3.8
│ ├── buffer-crc32@0.2.1
│ ├─┬ commander@1.2.0
│ │ └── keypress@0.1.0
│ ├─┬ connect@2.8.8
│ │ ├── bytes@0.2.0
│ │ ├── formidable@1.0.14
│ │ ├── pause@0.0.1
│ │ ├── qs@0.6.5
│ │ └── uid2@0.0.2
│ ├── cookie@0.1.0
│ ├── cookie-signature@1.0.1
│ ├─┬ debug@2.1.3
│ │ └── ms@0.7.0
│ ├── fresh@0.2.0
│ ├── methods@0.0.1
│ ├── mkdirp@0.3.5
│ ├── range-parser@0.0.4
│ └─┬ send@0.1.4
│ └── mime@1.2.11
├─┬ express-session@1.11.1
│ ├── cookie@0.1.2
│ ├── cookie-signature@1.0.6
│ ├── crc@3.2.1
│ ├─┬ debug@2.1.3
│ │ └── ms@0.7.0
│ ├── depd@1.0.1
│ ├── on-headers@1.0.0
│ ├── parseurl@1.3.0
│ ├─┬ uid-safe@1.1.0
│ │ ├── base64-url@1.2.1
│ │ └── native-or-bluebird@1.1.2
│ └── utils-merge@1.0.0
├─┬ morgan@1.5.2
│ ├── basic-auth@1.0.0
│ ├─┬ debug@2.1.3
│ │ └── ms@0.7.0
│ ├── depd@1.0.1
│ └─┬ on-finished@2.2.0
│ └── ee-first@1.1.0
├─┬ npmlog@0.0.4
│ └── ansi@0.1.2
├─┬ passport@0.2.1
│ ├── passport-strategy@1.0.0
│ └── pause@0.0.1
├─┬ passport-google-oauth2@0.1.6
│ └─┬ passport-oauth2@1.1.2
│ ├── oauth@0.9.12
│ ├── passport-strategy@1.0.0
│ └── uid2@0.0.3
├── q@0.9.7
├── redis@0.8.6
└─┬ request@2.27.0
├── aws-sign@0.3.0
├── cookie-jar@0.3.0
├── forever-agent@0.5.2
├─┬ form-data@0.1.4
│ ├── async@0.9.0
│ └─┬ combined-stream@0.0.7
│ └── delayed-stream@0.0.5
├─┬ hawk@1.0.0
│ ├── boom@0.4.2
│ ├── cryptiles@0.2.2
│ ├── hoek@0.9.1
│ └── sntp@0.2.4
├─┬ http-signature@0.10.1
│ ├── asn1@0.1.11
│ ├── assert-plus@0.1.5
│ └── ctype@0.5.3
├── json-stringify-safe@5.0.0
├── mime@1.2.11
├── node-uuid@1.4.3
├── oauth-sign@0.3.0
├── qs@0.6.6
└── tunnel-agent@0.3.0
b4@0.0.1
├─┬ 连接-redis@1.4.7
│ ├─┬ debug@2.1.3
│ │ └── ms@0.7.0
│ └── redis@0.10.3
├─┬ 饼干-parser@1.3.4
│ ├── cookie@0.1.2
│ └── 饼干-signature@1.0.6
├─┬ express@3.3.8
│ ├── 缓冲区-crc32@0.2.1
│ ├─┬ commander@1.2.0
│ │ └── keypress@0.1.0
│ ├─┬ connect@2.8.8
│ │ ├── bytes@0.2.0
│ │ ├── formidable@1.0.14
│ │ ├── pause@0.0.1
│ │ ├── qs@0.6.5
│ │ └── uid2@0.0.2
│ ├── cookie@0.1.0
│ ├── 饼干-signature@1.0.1
│ ├─┬ debug@2.1.3
│ │ └── ms@0.7.0
│ ├── fresh@0.2.0
│ ├── methods@0.0.1
│ ├── mkdirp@0.3.5
│ ├── 射程-parser@0.0.4
│ └─┬ send@0.1.4
│ └── mime@1.2.11
├─┬ 快车-session@1.11.1
│ ├── cookie@0.1.2
│ ├── 饼干-signature@1.0.6
│ ├── crc@3.2.1
│ ├─┬ debug@2.1.3
│ │ └── ms@0.7.0
│ ├── depd@1.0.1
│ ├── 在-headers@1.0.0
│ ├── parseurl@1.3.0
│ ├─┬ 液体-safe@1.1.0
│ │ ├── base64-url@1.2.1
│ │ └── 本地或-bluebird@1.1.2
│ └── 乌提尔斯-merge@1.0.0
├─┬ morgan@1.5.2
│ ├── 基本的-auth@1.0.0
│ ├─┬ debug@2.1.3
│ │ └── ms@0.7.0
│ ├── depd@1.0.1
│ └─┬ 在-finished@2.2.0
│ └── ee-first@1.1.0
├─┬ npmlog@0.0.4
│ └── ansi@0.1.2
├─┬ passport@0.2.1
│ ├── 护照-strategy@1.0.0
│ └── pause@0.0.1
├─┬ 谷歌护照-oauth2@0.1.6
│ └─┬ 护照-oauth2@1.1.2
│ ├── oauth@0.9.12
│ ├── 护照-strategy@1.0.0
│ └── uid2@0.0.3
├── q@0.9.7
├── redis@0.8.6
└─┬ request@2.27.0
├── 自动气象站-sign@0.3.0
├── 饼干-jar@0.3.0
├── 永远-agent@0.5.2
├─┬ 形式-data@0.1.4
│ ├── async@0.9.0
│ └─┬ 合二为一-stream@0.0.7
│ └── 耽搁-stream@0.0.5
├─┬ hawk@1.0.0
│ ├── boom@0.4.2
│ ├── cryptiles@0.2.2
│ ├── hoek@0.9.1
│ └── sntp@0.2.4
├─┬ http-signature@0.10.1
│ ├── asn1@0.1.11
│ ├── 断言-plus@0.1.5
│ └── ctype@0.5.3
├── json字符串化-safe@5.0.0
├── mime@1.2.11
├── 节点-uuid@1.4.3
├── 非统组织-sign@0.3.0
├── qs@0.6.6
└── 隧道-agent@0.3.0
幸运的是,我在网站上发现了类似的问题
,这让我想到了去启用
Google+API
,它被“关闭”(噢,我!!,他第一个基于Google+的应用程序的天真开发人员)。这是问题的根源。我再次尝试,oauth2开始正确接收配置文件。您正在使用的范围
现在已被弃用:
passport.authenticate('google', { successRedirect: '/',scope:
[ 'https://www.googleapis.com/auth/userinfo.email']})
);
相反,我们必须使用以下方法:
passport.authenticate('google', { successRedirect: '/',scope:
['email']
}));
您还可以获得配置文件范围
:
passport.authenticate('google', { successRedirect: '/',scope:
[ 'email', 'profile' ]
}));
我正在使用Google OAuth 2.0游乐场,在我的例子中,这个错误的原因是我的令牌已经过期。在操场中刷新它解决了问题。我发现了相同的错误,并通过以下操作解决了问题:
在package.json中,将“passport”值更改为“^0.4.0”,将“passport google oauth”更改为“^2.0.0”。再次运行“npm安装”。我也面临同样的问题! 解决方案:内部
passport.use(谷歌新战略)({ clientID:“一个特定的值”, clientSecret:“另一个特定的值”, 回调URL:“http://127.0.0.1:3000/auth/google/callback", passReqToCallback:正确, ********************************* }, 在第行添加此链接“https://www.googleapis.com/oauth2/v3/userinfo" 最终代码如下所示 passport.use(谷歌新战略)({ clientID:GOOGLE\u客户端\u ID, clientSecret:。谷歌\u客户端\u密码, 回调URL:“http://localhost:3000/auth/google/secrets", passReqToCallback:正确, userProfileURL:“https://www.googleapis.com/oauth2/v3/userinfo" },
这个希望解决了问题!经过一些研究,我的案例中出现问题的根本原因是我最初使用了
userProfileURL:"https://googleapis.com/oauth2/v3/userinfo" (WRONG)
而不是使用
userProfileURL:"https://**www**.googleapis.com/oauth2/v3/userinfo"
我也有不推荐使用的作用域
https://www.googleapis.com/auth/userinfo.profile
和https://www.googleapis.com/auth/userinfo.email
分别更改为profile
和email
。哇,谢谢你花了这么多时间在这上面。他们真的应该会返回某种错误!对我来说,回调会很重要t回答。“他第一个基于Google+的应用程序的天真开发人员”-:)在我的例子中,我已经打开了它,但我只需要等几分钟,它就可以在Google服务器上传播。这里的解决方案是正确的!!!谢谢你救了我。