<commit_before>var util = require('util');
var uri = require('url');
var crypto = require('crypto');
var OAuth2Strategy = require('passport-oauth2');
var InternalOAuthError = require('passport-oauth2').InternalOAuthError;

util.inherits(FacebookTokenStrategy, OAuth2Strategy);

/**
 * `FacebookTokenStrategy` constructor.
 *
 * The Facebook authentication strategy authenticates requests by delegating to
 * Facebook using the OAuth 2.0 protocol.
 *
 * Applications must supply a `verify` callback which accepts an `accessToken`,
 * `refreshToken` and service-specific `profile`, and then calls the `done`
 * callback supplying a `user`, which should be set to `false` if the
 * credentials are not valid.  If an exception occurred, `error` should be set.
 *
 * Options:
 *   - `clientID`      your Facebook application's App ID
 *   - `clientSecret`  your Facebook application's App Secret
 *
 * Examples:
 *
 *     passport.use(new FacebookTokenStrategy({
 *         clientID: '123-456-789',
 *         clientSecret: '<PASSWORD>'
 *       },
 *       function(accessToken, refreshToken, profile, done) {
 *         User.findOrCreate(..., function (err, user) {
 *           done(err, user);
 *         });
 *       }
 *     ));
 *
 * @param {Object} options
 * @param {Function} verify
 * @api public
 */
function FacebookTokenStrategy(options, verify) {
  options = options || {};
  options.authorizationURL = options.authorizationURL || 'https://www.facebook.com/v2.2/dialog/oauth';
  options.tokenURL = options.tokenURL || 'https://graph.facebook.com/oauth/access_token';
  options.scopeSeparator = options.scopeSeparator || ',';

  OAuth2Strategy.call(this, options, verify);

  this.name = 'facebook-token';
  this._passReqToCallback = options.passReqToCallback;
  this._profileURL = options.profileURL || 'https://graph.facebook.com/v2.2/me';
  this._clientSecret = options.clientSecret;
  this._enableProof = options.enableProof;
  this._profileFields = options.profileFields || null;
  this._oauth2._useAuthorizationHeaderForGET = false;
}

/**
 * Authenticate request by delegating to a service provider using OAuth 2.0.
 * @param {Object} req
 * @param {Object} options
 * @api protected
 */
FacebookTokenStrategy.prototype.authenticate = function(req, options) {
  var self = this;
  accessToken = (req.body && req.body.access_token) || (req.query && req.query.access_token) || (req.headers && req.headers.access_token),
  refreshToken = (req.body && req.body.refresh_token) || (req.query && req.query.refresh_token) || (req.headers && req.headers.refresh_token);

  if (!accessToken) {
    return this.fail({
      message: 'You should provide access_token'
    });
  }

  self._loadUserProfile(accessToken, function(error, profile) {
    if (error) return self.fail(error);

    function verified(error, user, info) {<commit_msg>Allow to change default field for access_token and refresh_token.<commit_after>var util = require('util');
var uri = require('url');
var crypto = require('crypto');
var OAuth2Strategy = require('passport-oauth2');
var InternalOAuthError = require('passport-oauth2').InternalOAuthError;

util.inherits(FacebookTokenStrategy, OAuth2Strategy);

/**
 * `FacebookTokenStrategy` constructor.
 *
 * The Facebook authentication strategy authenticates requests by delegating to
 * Facebook using the OAuth 2.0 protocol.
 *
 * Applications must supply a `verify` callback which accepts an `accessToken`,
 * `refreshToken` and service-specific `profile`, and then calls the `done`
 * callback supplying a `user`, which should be set to `false` if the
 * credentials are not valid.  If an exception occurred, `error` should be set.
 *
 * Options:
 *   - `clientID`      your Facebook application's App ID
 *   - `clientSecret`  your Facebook application's App Secret
 *
 * Examples:
 *
 *     passport.use(new FacebookTokenStrategy({
 *         clientID: '123-456-789',
 *         clientSecret: '<PASSWORD>'
 *       },
 *       function(accessToken, refreshToken, profile, done) {
 *         User.findOrCreate(..., function (err, user) {
 *           done(err, user);
 *         });
 *       }
 *     ));
 *
 * @param {Object} options
 * @param {Function} verify
 * @api public
 */
function FacebookTokenStrategy(options, verify) {
  options = options || {};
  options.authorizationURL = options.authorizationURL || 'https://www.facebook.com/v2.2/dialog/oauth';
  options.tokenURL = options.tokenURL || 'https://graph.facebook.com/oauth/access_token';
  options.scopeSeparator = options.scopeSeparator || ',';

  OAuth2Strategy.call(this, options, verify);

  this.name = 'facebook-token';
  this._accessTokenField = options.accessTokenField || 'access_token';
  this._refreshTokenField = options.refreshTokenField || 'refresh_token';
  this._passReqToCallback = options.passReqToCallback;
  this._profileURL = options.profileURL || 'https://graph.facebook.com/v2.2/me';
  this._clientSecret = options.clientSecret;
  this._enableProof = options.enableProof;
  this._profileFields = options.profileFields || null;
  this._oauth2._useAuthorizationHeaderForGET = false;
}

/**
 * Authenticate request by delegating to a service provider using OAuth 2.0.
 * @param {Object} req
 * @param {Object} options
 * @api protected
 */
FacebookTokenStrategy.prototype.authenticate = function(req, options) {
  var self = this;
  accessToken = (req.body && req.body[self._accessTokenField]) || (req.query && req.query[self._accessTokenField]) || (req.headers && req.headers[self._accessTokenField]),
  refreshToken = (req.body && req.body[self._refreshTokenField]) || (req.query && req.query[self._refreshTokenField]) || (req.headers && req.headers[self._refreshTokenField]);

  if (!accessToken) {
    return this.fail({
      message: 'You should provide access_token'
    });
  }

  self._loadUserProfile(accessToken, function(error, profile) {
    if (error) return self.fail(error);

    function verified(error, user, info) {
{'fraction_non_alphanumeric': 0.13258275920013443, 'fraction_numerical': 0.007729793312048395, 'mean_word_length': 4.11340206185567, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6995394', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1712, 'n_words': 426}