Passport js 错误 401:invalid_client 找不到 OAuth 客户端
Passport js Error 401: invalid_client The OAuth client was not found
我在 Express 中使用 Passport js 对 Google 的用户进行身份验证。我将 Passport
用于 oauth 服务,将 passport-google-oauth20
用于 Google 策略,并将 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
自动 运行ning 服务器。我还在 google.developers.console
中为 client_id 和 client_secret 创建了项目。但是当我 运行 服务器时,它只是将我重定向到以下 url 并显示以下错误。
url: https://accounts.google.com/signin/oauth/error?authError=Cg5pbnZhbGlkX2NsaWVudBIfVGhlIE9BdXRoIGNsaWVudCB3YXMgbm90IGZvdW5kLiCRAw%3D%3D&client_id=z02cLybsfbgFxwA3d60Iuc5u
错误:
clientID: key.googleClientSecret,
clientSecret: key.googleClientSecret,
您将 googleClientSecret
设置为 clientID。这似乎不对:)
我在 Express 中使用 Passport js 对 Google 的用户进行身份验证。我将 Passport
用于 oauth 服务,将 passport-google-oauth20
用于 Google 策略,并将 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
自动 运行ning 服务器。我还在 google.developers.console
中为 client_id 和 client_secret 创建了项目。但是当我 运行 服务器时,它只是将我重定向到以下 url 并显示以下错误。
url: https://accounts.google.com/signin/oauth/error?authError=Cg5pbnZhbGlkX2NsaWVudBIfVGhlIE9BdXRoIGNsaWVudCB3YXMgbm90IGZvdW5kLiCRAw%3D%3D&client_id=z02cLybsfbgFxwA3d60Iuc5u
错误:
clientID: key.googleClientSecret,
clientSecret: key.googleClientSecret,
您将 googleClientSecret
设置为 clientID。这似乎不对:)