【问题标题】:Google oauth2.0 showing Invalid client error谷歌 oauth2.0 显示无效客户端错误
【发布时间】:2019-01-21 18:26:31
【问题描述】:

我正在尝试在此应用程序中设置 google Oauth。我已经为远程服务器和生产服务器创建了配置。它在开发环境中运行良好,但在生产环境中出现此错误,即 Heroku。

遇到这个错误:

401. That’s an error.

Error: invalid_client

The OAuth client was not found.

Request Details
response_type=code
redirect_uri=https://vast-ridge-80091.herokuapp.com/auth/google/callback
scope=profile email
client_id=process.env.GOOGLE_CLIENT_ID

从这个终点:https://vast-ridge-80091.herokuapp.com/auth/google

这是我的生产环境配置设置

module.exports = {

googleClientID:'process.env.GOOGLE_CLIENT_ID',
googleClientSecret:'process.env.GOOGLE_CLIENT_SECRET',
monoURI:'process.env.MONGO_URI',
cookieKey:'process.env.COOKIE_KEY'

};



if(process.env.NODE_ENV === 'production'){
module.exports = require('./prod');
}else{
module.exports = require('./dev');
}

我已经更新了 heroku 应用设置中的 env 变量并仔细检查了所有内容,这些凭据是正确的。

这是我的 Heroku 日志:

remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:        NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  unspecified
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version 10.x...
remote:        Downloading and installing node 10.15.0...
remote:        Using default npm version: 6.4.1
remote:
remote: -----> Building dependencies
remote:        Installing node modules (package.json + package-lock)
remote:
remote:        > node-sass@4.11.0 install         
/tmp/build_e5f416e2f810c6ecc625fbcb71d64ab7/node_modules/node-sass
remote:        > node scripts/install.js
remote:
remote:        Downloading binary from https://github.com/sass/node-    
sass/releases/download/v4.11.0/linux-x64-64_binding.node
remote:        Download complete
remote:        Binary saved to     
/tmp/build_e5f416e2f810c6ecc625fbcb71d64ab7/node_modules/node-        
 sass/vendor/linux-x64-64/binding.node
remote:        Caching binary to /tmp/npmcache.hFNmC/node-sass/4.11.0/linux- 
x64-64_binding.node
remote:
remote:        > node-sass@4.11.0 postinstall     
/tmp/build_e5f416e2f810c6ecc625fbcb71d64ab7/node_modules/node-sass
remote:        > node scripts/build.js
remote:
remote:        Binary found at 
/tmp/build_e5f416e2f810c6ecc625fbcb71d64ab7/node_modules/node- 
sass/vendor/linux-x64-64/binding.node
remote:        Testing binary
remote:        Binary is fine
remote:        added 305 packages from 198 contributors and audited 811 
packages in 9.098s
remote:        found 0 vulnerabilities
remote:
remote:
remote: -----> Caching build
remote:        - node_modules
remote:
remote: -----> Pruning devDependencies
remote:        audited 811 packages in 2.556s
remote:        found 0 vulnerabilities
remote:
remote:
remote: -----> Build succeeded!
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> web
remote:
remote: -----> Compressing...
remote:        Done: 25.9M
remote: -----> Launching...
remote:        Released v3
remote:        https://vast-ridge-80091.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.

我尝试了一些在这里讨论的解决方案:invalid_client in google oauth2

但还是没有运气。

任何形式的帮助都会是一种幸福。

【问题讨论】:

  • 查看谷歌应用中的回复网址
  • 这是回复网址:accounts.google.com/o/oauth2/v2/…@Max
  • 您发布的网址上的 redirect_uri 是:https://vast-ridge-80091.herokuapp.com/auth/google/callback 这对远程和生产都正确吗?

标签: javascript node.js heroku oauth-2.0 passport.js


【解决方案1】:

回复网址

https://accounts.google.com/o/oauth2/v2/auth?response_type=code&redirect_uri=https://vast-ridge-80091.herokuapp.com/auth/google/callback&scope=profile email&client_id=process.env.GOOGLE_CLIENT_ID

包含 client_id

上的错误

client_id=process.env.GOOGLE_CLIENT_ID

您必须将 process.env.GOOGLE_CLIENT_ID 替换为 client_id

【讨论】:

  • 其实 GOOGLE_CLIENT_ID 来自 heroku,环境变量和秘密都保存在其中。 @Max
猜你喜欢
  • 2015-09-29
  • 1970-01-01
  • 2014-07-24
  • 2020-07-25
  • 1970-01-01
  • 2018-11-02
  • 1970-01-01
  • 2018-03-26
  • 2016-03-31
相关资源
最近更新 更多