If you have any query feel free to chat us!
Happy Coding! Happy Learning!
To set up passport-google-oauth20 in your application, follow these steps:
Copy code
npm install passport passport-google-oauth20
javascriptCopy code
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
passport.use(new GoogleStrategy({
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: '/auth/google/callback'
},
function(accessToken, refreshToken, profile, cb) {
// User authentication and/or registration code here
return cb(null, profile);
}
));
javascriptCopy code
const express = require('express');
const passport = require('passport');
const router = express.Router();
// Google authentication route
router.get('/auth/google',
passport.authenticate('google', { scope: ['profile'] }));
// Google authentication callback route
router.get('/auth/google/callback',
passport.authenticate('google', { failureRedirect: '/login' }),
function(req, res) {
// Successful authentication, redirect to the home page
res.redirect('/');
});
passport.authenticate()
middleware to authenticate requests to your protected routes:javascriptCopy code
const express = require('express');
const router = express.Router();
// Protected route
router.get('/protected',
passport.authenticate('google', { session: false }),
function(req, res) {
// The user is authenticated, respond with a success message
res.send('You are authenticated!');
});
Note: In step 4, the callback function receives an accessToken
, a refreshToken
, a profile
, and a cb
(callback) function. You will need to implement the user authentication and/or registration code in this function.
Comments: 2
I am not able to access videos from second class and further. I have already completed first class
When will I get my course?
Now, Your query was resolved.