Reputation: 9
I was previously using passport-google-oauth20
in my Node.js application to handle Google social login. Here's a snippet of my implementation:
const login_passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
login_passport.use(
new GoogleStrategy(
{
clientID: process.env.GOOGLE_CLI_ID,
clientSecret: process.env.GOOGLE_CLI_KEY,
callbackURL: process.env.GOOGLE_CALLBACK,
},
async (accessToken, refreshToken, profile, done) => {
try {
const user = {
profile: profile,
accessToken: accessToken,
refreshToken: refreshToken,
};
return done(null, user);
} catch (error) {
console.error(
"Error fetching additional details:",
error.response ? error.response.data : error.message
);
return done(error);
}
}
)
);
router.get(
'/auth/google',
login_passport.authenticate('google', {
scope: ['profile', 'email'],
prompt: 'select_account',
})
);
router.get(
'/register-google-user',
login_passport.authenticate('google', {
successRedirect: '/api/v1/fe/auth/successful',
failureRedirect: '/api/v1/fe/auth/failure',
})
);
router.get('/auth/successful', fe_controllers.google_sign_up);
Recently, Google updated its OAuth policy and terms and now requires additional compliance. My existing implementation no longer works as expected, and I need to update my integration to comply with the new terms.
How can I update my passport-google-oauth20
strategy to align with Google's new requirements?
Is there a newer library or best practice for handling Google social login in Node.js?
What changes do I need to make in the scope
, callback URL, or other settings to comply with the latest policies?
Any guidance, example code, or documentation links would be greatly appreciated. Thanks in advance!
Upvotes: 0
Views: 30