<commit_before>'use strict';

var googleapis = require('googleapis');
var OAuth2Client = googleapis.OAuth2Client;

var retrieveFiles = require('./helpers/retrieve.js');
var uploadFiles = require('./helpers/upload.js');

module.exports = function(config) {
  var init = function(req, next) {
    googleapis.execute(function(err) {
      if(err) {
        return next(err);
      }

      var oauth2Client = new OAuth2Client(config.gdrive_id, config.gdrive_secret, config.gdrive_callback);

      // generate consent page url for Google Drive access, even when user is not connected (offline)
      var redirectUrl = oauth2Client.generateAuthUrl({
        access_type: 'offline',
        scope: 'https://www.googleapis.com/auth/drive.readonly',
        approval_prompt: "force"
      });

      redirectUrl += '&state=' + req.params.code;

      next(null, {code: req.params.code}, redirectUrl);
    });
  };

  var retrievePreDatasIdentifier = function(req, next) {
    if(!req.params.state) {
      return next("State parameter left out of query.");
    }

    next(null, {'datas.code': req.params.state});
  };

  var retrieveAuthDatas = function(req, preDatas, next) {
    var oauth2Client = new OAuth2Client(config.google_id, config.google_secret, config.google_callback);
    // request tokens set
    oauth2Client.getToken(req.params.code, function(err, tokens) {
      if(err) {
        return next(new Error(err));
      }<commit_msg>Fix production auth<commit_after>'use strict';

var googleapis = require('googleapis');
var OAuth2Client = googleapis.OAuth2Client;

var retrieveFiles = require('./helpers/retrieve.js');
var uploadFiles = require('./helpers/upload.js');

module.exports = function(config) {
  var init = function(req, next) {
    googleapis.execute(function(err) {
      if(err) {
        return next(err);
      }

      var oauth2Client = new OAuth2Client(config.google_drive_id, config.google_drive_secret, config.google_drive_callback);

      // generate consent page url for Google Drive access, even when user is not connected (offline)
      var redirectUrl = oauth2Client.generateAuthUrl({
        access_type: 'offline',
        scope: 'https://www.googleapis.com/auth/drive.readonly',
        approval_prompt: "force"
      });

      redirectUrl += '&state=' + req.params.code;

      next(null, {code: req.params.code}, redirectUrl);
    });
  };

  var retrievePreDatasIdentifier = function(req, next) {
    if(!req.params.state) {
      return next("State parameter left out of query.");
    }

    next(null, {'datas.code': req.params.state});
  };

  var retrieveAuthDatas = function(req, preDatas, next) {
    var oauth2Client = new OAuth2Client(config.google_drive_id, config.google_drive_secret, config.google_drive_callback);
    // request tokens set
    oauth2Client.getToken(req.params.code, function(err, tokens) {
      if(err) {
        return next(new Error(err));
      }
{'fraction_non_alphanumeric': 0.1292749658002736, 'fraction_numerical': 0.005471956224350205, 'mean_word_length': 3.452054794520548, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4992093', 'n_tokens_mistral': 898, 'n_tokens_neox': 876, 'n_words': 196}