Я использую Google Plus API в одном из своих приложений. Он отлично работает в моем локальном хранилище, но на Heroku выдает эту ошибку:
Ошибка: redirect_uri_mismatch
URI перенаправления в запросе, http://discuss -my-anime.herokuapp.com / auth / google / redirect , не соответствует авторизованным для клиента OAuth.
Мои учетные данные Google Plus API приведены ниже:
учетные данные Google plus API
Я использую паспортный пакет для аутентификации, и мой код установки паспорта указан ниже:
const passport = require("passport");
const GoogleStrategy = require("passport-google-oauth20");
const keys = require("./keys");
const User = require("../models/user-model");
passport.serializeUser((user, done)=>{
done(null, user.id);
});
passport.deserializeUser((id, done)=>{
User.findById(id).then((user)=>{
done(null, user);
});
});
passport.use(
new GoogleStrategy({
//options for google strategy
callbackURL: "/auth/google/redirect",
clientID: keys.google.clientID,
clientSecret: keys.google.clientSecret
}, (accessToken, refreshToken, profile, done)=>{
//check if user already exists
User.findOne({googleId: profile.id}).then((currentUser)=>{
if(currentUser){
//already have a user
console.log("user is: " + currentUser);
done(null, currentUser);
}
else{
//creating new user
new User({
username: profile.displayName,
googleId: profile.id,
thumbnail: profile._json.picture
}).save().then((newUser)=>{
console.log("new user created: " + newUser);
done(null, newUser);
});
}
});
})
);