Github Strategy is defined, though it's not accepting solution

Tell us what’s happening:
https://cm-fcc-social-authentication.glitch.me
I’ve properly working code but task is not accepting the solution. GithubStratagy is used properly though it’s denying. Can someone help me out?

Your code so far

        "use strict";

const express = require("express");
const bodyParser = require("body-parser");
const fccTesting = require("./freeCodeCamp/fcctesting.js");
const session = require("express-session");
const mongo = require("mongodb").MongoClient;
const passport = require("passport");
const GitHubStrategy = require("passport-github").Strategy;

const app = express();

fccTesting(app); //For FCC testing purposes

app.use("/public", express.static(process.cwd() + "/public"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.set("view engine", "pug");

mongo.connect(process.env.DATABASE, (err, res) => {
  if (err) {
    console.log("Database error: " + err);
  } else {
    console.log("Successful database connection");
    var db = res.db("test");
    app.use(
      session({
        secret: process.env.SESSION_SECRET,
        resave: true,
        saveUninitialized: true
      })
    );
    app.use(passport.initialize());
    app.use(passport.session());

    function ensureAuthenticated(req, res, next) {
      if (req.isAuthenticated()) {
        return next();
      }
      res.redirect("/");
    }

    passport.serializeUser((user, done) => {
      done(null, user.id);
    });

    passport.deserializeUser((id, done) => {
      db.collection("users").findOne({ id: id }, (err, doc) => {
        console.log("deser", doc);
        done(null, doc);
      });
    });

    /*
     *  ADD YOUR CODE BELOW
     */

    passport.use(
      new GitHubStrategy(
        {
          clientID: process.env.GITHUB_CLIENT_ID,
          clientSecret: process.env.GITHUB_CLIENT_SECRET,
          callbackURL:
            "https://cm-fcc-social-authentication.glitch.me/auth/github/callback"
        },
        function(accessToken, refreshToken, profile, cb) {
          console.log(profile);
          //Database logic here with callback containing our user object
          
        }
      )
    );
    app.route("/auth/github").get(passport.authenticate("github"));

    app
      .route("/auth/github/callback")
      .get(
        passport.authenticate("github", { failureRedirect: "/" }),
        (req, res) => {
          res.redirect("/profile");
        }
      );
    /*
     *  ADD YOUR CODE ABOVE
     */

    app.route("/").get((req, res) => {
      res.render(process.cwd() + "/views/pug/index");
    });

    app.route("/profile").get(ensureAuthenticated, (req, res) => {
      res.render(process.cwd() + "/views/pug/profile", { user: req.user });
    });

    app.route("/logout").get((req, res) => {
      req.logout();
      res.redirect("/");
    });

    app.use((req, res, next) => {
      res
        .status(404)
        .type("text")
        .send("Not Found");
    });

    app.listen(process.env.PORT || 3000, () => {
      console.log("Listening on port " + process.env.PORT);
    });
  }
});

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0.

Challenge: Advanced Node and Express - Implementation of Social Authentication II

Link to the challenge:
https://www.freecodecamp.org/learn/information-security-and-quality-assurance/advanced-node-and-express/implementation-of-social-authentication-ii

1 Like

Hi @CUManiar,

The tests for this challenge are using regex to make sure you’re server.js file contains certain statements. The current tests can be tripped up by newlines. I would try removing the newlines after passport.use( and callbackURL: and see if that works.

FYI- you can see the details of the tests here.

3 Likes

That actually worked. Thanks man!