Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
138 views
in Technique[技术] by (71.8m points)

javascript - Passport-Google-Auth is not working. with .JS?

Trying to add Google Login to the Website, I have created Project on Google Developers Console, Created the OAuth Credential and added the Client_ID and Client_Secret to.env file.

Code below :

passport.use(
new GoogleStrategy(
{
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
callbackURL: "http://localhost:3000/auth/google/secrets",
userProfileURL: "https://www.googleapis.com/oauth2/v3/userinfo",
},
function (accessToken, refreshToken, profile, cb) {
User.findOrCreate({ googleId: profile.id }, function (err, user) {
return cb(err, user);
});
}
)
);

I have also added the plugin for findorCreate:

const findOrCreate = require("mongoose-findorcreate");
userSchema.plugin(findOrCreate);

callback URL is also proper:

And finally this my get method.

app.get("/auth/google", function (req, res) {
passport.authenticate("google", { scope: ["profile"] });
});
question from:https://stackoverflow.com/questions/65868769/passport-google-auth-is-not-working-with-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...