Skip to content

Instantly share code, notes, and snippets.

Last active March 25, 2023 09:34
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save godfreyd/68af82df0bc171da54971990f442dddb to your computer and use it in GitHub Desktop.
var passport = require('passport'),
YoutubeV3Strategy = require('passport-youtube-v3').Strategy,
env = process.env;
try {
var config = require('./config'),
servicesYouTube =;
} catch (err) {}
var clientID = env.YOUTUBE_APP_ID || servicesYouTube.client_id,
clientSecret = env.YOUTUBE_APP_SECRET || servicesYouTube.client_secret;
if (!clientID || !clientSecret) {
console.error('Please provide youtube app id and youtube app secret via ENV vars or add config.json (see config.example.json for reference).');
function verify(accessToken, refreshToken, profile, done) {
if (!profile) return done(null, false);
return done(null, {
token: accessToken,
refreshtoken: refreshToken,
profile: JSON.parse(profile._raw)
// serialize user into the session
passport.serializeUser(function(user, done) {
done(null, user);
passport.deserializeUser(function(user, done) {
done(null, user);
passport.use(new YoutubeV3Strategy({
clientID: clientID,
clientSecret: clientSecret,
callbackURL: '/auth/youtube/callback',
scope: ['']
}, verify));
module.exports = passport;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment