node.js - Passport js 错误 401:invalid_client 找不到 OAuth 客户端
问题描述
我在 Express 中使用 Passport js 对 Google 用户进行身份验证。我Passport
用于 oauth 服务和passport-google-oauth20
GoogleStrategy,我Express
用于服务器端。所以以下是我的代码....
const express = require('express')
const passport = require('passport')
const GoogleStrategy = require('passport-google-oauth20').Strategy
const key = require('./config/key')
const app = express()
passport.use(new GoogleStrategy({
clientID: key.googleClientSecret,
clientSecret: key.googleClientSecret,
callbackURL: '/auth/google/callback'
},(accessToken)=>{
console.log(accessToken)
})
)
app.get('/auth/google',passport.authenticate('google', {
scope: ['profile','email']
}))
app.get('/auth/google/callback',passport.authenticate('google'))
const PORT = process.env.PORT || 5000
app.listen(PORT)
以下是我的 package.json 脚本
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
}
我正在使用nodemon
自动运行服务器。而且我还google.developers.console
为client_id和client_secret创建了项目。但是当我运行服务器时,它只是将我重定向到以下 url 并显示以下错误。
网址:https://accounts.google.com/signin/oauth/error?authError=Cg5pbnZhbGlkX2NsaWVudBIfVGhlIE9BdXRoIGNsaWVudCB3YXMgbm90IGZvdW5kLiCRAw%3D%3D&client_id=z02cLybsfbgFxwA3d60Iuc5u
解决方案
clientID: key.googleClientSecret,
clientSecret: key.googleClientSecret,
您将 设置googleClientSecret
为 clientID。这似乎不对:)
推荐阅读
- javascript - 我可以使用 javascript 为对象设置条件变量吗?
- networking - 输入域名时 ERR_CONNECTION_REFUSED 但输入公网 IP 地址时 OK
- node.js - 当开发人员在多个系统上时,为 NPM 脚本放置什么?
- firebase - 应用程序进入后台时可扩展的 FCM 通知模型
- python - 包含点积的函数的 np.vectorize
- c - 字符串数组。编译器错误。也许内存超出范围?
- scala - 播放框架/Akka Streams:检测 WebSocket 何时关闭
- angular - 如何确认 Angular App Proxy 工作正常 (v7)
- c# - 有没有办法使用 bool 来检测 foreach 循环中的错误值,这样我的方法就不会执行?
- c# - 仅提取某些索引