<commit_before>var getAuthHeader  = require('basic-auth'),
    bcrypt         = require('bcrypt-nodejs'),
    request        = require('request-promise'),
    handleError    = require('../util.js').handleError,
    userController = require('../api/users/userController.js');

// Check if we are in deployed state and if not, require the _private-config.json file   
if(process.env.FACEBOOK_APP_ID === undefined && process.env.FACEBOOK_APP_SECRET === undefined){
  var  CONF             = require('../../_private-config.json');
}



var Facebook = {};
Facebook.getTokenData = function (accessToken) {
  // Check if process.env Facebook keys are available
  if(process.env.FACEBOOK_APP_ID === undefined && process.env.FACEBOOK_APP_SECRET === undefined){
    var debugTokenURL = 'https://graph.facebook.com/debug_token' 
      + '?input_token=' + accessToken
      + '&access_token=' + CONF.FACEBOOK_APP_ID +'|'+ CONF.FACEBOOK_APP_SECRET;
  } else {
    var debugTokenURL = 'https://graph.facebook.com/debug_token' 
      + '?input_token=' + accessToken
      + '&access_token=' + process.env.FACEBOOK_APP_ID +'|'+ process.env.FACEBOOK_APP_SECRET;
  }

  return request(debugTokenURL);
};

Facebook.getAccessToken = function (authorizationCode) {
  // Check if process.env Facebook keys are available
  if(process.env.FACEBOOK_APP_ID === undefined && process.env.FACEBOOK_APP_SECRET === undefined){
    var getAccessTokenURL = 'https://graph.facebook.com/v2.5/oauth/access_token'
      + '?client_id=' + CONF.FACEBOOK_APP_ID
      + '&redirect_uri=' + 'http://localhost:3000/auth/facebook/callback'
      + '&client_secret=' + CONF.FACEBOOK_APP_SECRET
      + '&code=' + authorizationCode;
    } else {
      var getAccessTokenURL = 'https://graph.facebook.com/v2.5/oauth/access_token'
      + '?client_id=' + process.env.FACEBOOK_APP_ID
      + '&redirect_uri=' + 'http://localhost:3000/auth/facebook/callback'
      + '&client_secret=' + process.env.FACEBOOK_APP_SECRET
      + '&code=' + authorizationCode;
    }

  return request(getAccessTokenURL);
};

// Redirects to a page on the client that automatically performs login
// operations, then redirects to dashboard
var redirectToAutomaticLogin = function (res, username, authToken) {
  res.redirect('/#/signin/auto?username='  + username
                            +'&authToken=' + authToken);
};

module.exports = {
  authenticate : function(req, res, next) {
    var user = getAuthHeader(req); // Parse information in Authorization header
    if (user) user.pass = new Buffer(user.pass, 'base64').toString('ascii'); // decode token
    if (user === undefined) {
      res.setHeader('WWW-Authenticate', 'Basic');
      res.status(401).end('Unauthorized');
<commit_msg>(fix) Correct deployed URL for Facebook auth<commit_after>var getAuthHeader  = require('basic-auth'),
    bcrypt         = require('bcrypt-nodejs'),
    request        = require('request-promise'),
    handleError    = require('../util.js').handleError,
    userController = require('../api/users/userController.js');

// Check if we are in deployed state and if not, require the _private-config.json file   
if(process.env.FACEBOOK_APP_ID === undefined && process.env.FACEBOOK_APP_SECRET === undefined){
  var  CONF             = require('../../_private-config.json');
}



var Facebook = {};
Facebook.getTokenData = function (accessToken) {
  // Check if process.env Facebook keys are available
  if(process.env.FACEBOOK_APP_ID === undefined && process.env.FACEBOOK_APP_SECRET === undefined){
    var debugTokenURL = 'https://graph.facebook.com/debug_token' 
      + '?input_token=' + accessToken
      + '&access_token=' + CONF.FACEBOOK_APP_ID +'|'+ CONF.FACEBOOK_APP_SECRET;
  } else {
    var debugTokenURL = 'https://graph.facebook.com/debug_token' 
      + '?input_token=' + accessToken
      + '&access_token=' + process.env.FACEBOOK_APP_ID +'|'+ process.env.FACEBOOK_APP_SECRET;
  }

  return request(debugTokenURL);
};

Facebook.getAccessToken = function (authorizationCode) {
  // Check if process.env Facebook keys are available
  if(process.env.FACEBOOK_APP_ID === undefined && process.env.FACEBOOK_APP_SECRET === undefined){
    var getAccessTokenURL = 'https://graph.facebook.com/v2.5/oauth/access_token'
      + '?client_id=' + CONF.FACEBOOK_APP_ID
      + '&redirect_uri=' + 'http://localhost:3000/auth/facebook/callback'
      + '&client_secret=' + CONF.FACEBOOK_APP_SECRET
      + '&code=' + authorizationCode;
    } else {
      var getAccessTokenURL = 'https://graph.facebook.com/v2.5/oauth/access_token'
      + '?client_id=' + process.env.FACEBOOK_APP_ID
      + '&redirect_uri=' + 'http://roadmaptoanything.herokuapp.com/auth/facebook/callback'
      + '&client_secret=' + process.env.FACEBOOK_APP_SECRET
      + '&code=' + authorizationCode;
    }

  return request(getAccessTokenURL);
};

// Redirects to a page on the client that automatically performs login
// operations, then redirects to dashboard
var redirectToAutomaticLogin = function (res, username, authToken) {
  res.redirect('/#/signin/auto?username='  + username
                            +'&authToken=' + authToken);
};

module.exports = {
  authenticate : function(req, res, next) {
    var user = getAuthHeader(req); // Parse information in Authorization header
    if (user) user.pass = new Buffer(user.pass, 'base64').toString('ascii'); // decode token
    if (user === undefined) {
      res.setHeader('WWW-Authenticate', 'Basic');
      res.status(401).end('Unauthorized');

{'fraction_non_alphanumeric': 0.14465065502183405, 'fraction_numerical': 0.0054585152838427945, 'mean_word_length': 3.638818565400844, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7087881', 'n_tokens_mistral': 1770, 'n_tokens_neox': 1724, 'n_words': 324}