Skip to content

Commit

Permalink
adding separate implementation of FB auth for instagram
Browse files Browse the repository at this point in the history
  • Loading branch information
platform-kit committed Jul 26, 2022
1 parent 70353a8 commit 24b1145
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
60 changes: 60 additions & 0 deletions routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var router = express.Router();
var passport = require("passport");
var TwitterStrategy = require("passport-twitter");
var FacebookStrategy = require("passport-facebook");
var InstagramStrategy = require("passport-facebook");
var MagicLinkStrategy = require("passport-magic-link").Strategy;
var GoogleStrategy = require("passport-google-oauth20").Strategy;
var YoutubeV3Strategy = require("passport-youtube-v3").Strategy;
Expand All @@ -17,6 +18,7 @@ var smtpTransport = require("nodemailer-smtp-transport");
var features = {
mail: false,
facebook: false,
instagram: false,
twitter: false,
google: false,
youtube: false,
Expand All @@ -41,6 +43,13 @@ if (
features.facebook = true;
}

if (
process.env.INSTAGRAM_APP_SECRET != null &&
process.env.INSTAGRAM_CLIENT_ID != null
) {
features.instagram = true;
}

if (
process.env.TWITTER_APP_ID != null &&
process.env.TWITTER_CONSUMER_API_KEY != null &&
Expand Down Expand Up @@ -82,6 +91,8 @@ if (
features.google = true;
}

console.log(features);

// Passport Config
passport.serializeUser(function (user, cb) {
process.nextTick(function () {
Expand Down Expand Up @@ -230,6 +241,55 @@ if (features.facebook == true) {
);
}

//////////////////////////////////////////////////////////////////////////////////////// Instagram
if (features.instagram == true) {
// Instagram Config
passport.use(
new InstagramStrategy(
{
clientID: process.env.INSTAGRAM_CLIENT_ID,
clientSecret: process.env.INSTAGRAM_APP_SECRET,
callbackURL: domain + "/auth/instagram/callback",
},
function (token, tokenSecret, profile, cb) {
var data = {
token: token,
tokenSecret: tokenSecret,
profile: profile,
};
//console.log(data);
return cb(null, data);
}
)
);
// Instagram Routes
var instagramScopes =
"email,pages_show_list,pages_read_engagement,instagram_content_publish,instagram_basic,pages_show_list";
if (
process.env.INSTAGRAM_SCOPES != null &&
process.env.INSTAGRAM_SCOPES != ""
) {
instagramScopes = process.env.INSTAGRAM_SCOPES;
}
instagramScopes = instagramScopes.split(",");
router.get(
"/auth/instagram",
passport.authenticate("facebook", { scope: instagramScopes })
);
router.get(
"/auth/instagram/callback",
passport.authenticate("facebook", { failureRedirect: "/login" }),
function (req, res) {
// Successful authentication, redirect home.
console.log(req.user);
var token = req.user.token;
var secret = req.user.tokenSecret;
var queryString = "?t=" + encodeURIComponent(token);
return res.redirect("/success" + queryString);
}
);
}

//////////////////////////////////////////////////////////////////////////////////////// Twitter
if (features.twitter == true) {
// Twitter Config
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
</a>
<a
v-if="platforms.facebook == true"
href="/auth/facebook"
href="/auth/instagram"
class="
btn
bg-white
Expand Down

0 comments on commit 24b1145

Please sign in to comment.