<commit_before>var Bluebird = require('bluebird');
var Errors = require('./errors');
var Sandbox = require('sandboxjs');
var Superagent = require('superagent');
var Http = require('http');
var Url = require('url');
var Open = require('opn');
var Chalk = require('chalk');
var Decode = require('jwt-decode');
var Assert = require('assert');
var Crypto = require('crypto');

module.exports = UserAuthenticator;

function UserAuthenticator (config) {
    if (!config) config = {};
    
    this.sandboxUrl = config.sandboxUrl || 'https://sandbox.auth0-extend.com';
    this.authorizationServer = config.authorizationServer;
    this.audience = config.audience;
    this.clientId = config.clientId;
    this.refreshToken = config.refreshToken;
}

// Discover whether WT deployment supports auth v2 and if so create
// UserAuthenticator instance for it
UserAuthenticator.create = function (sandboxUrl, auth0) {
    // TODO, tjanczuk, remove the following line when v2 auth exits beta
    // Until then, it is an experimental feature enabled with AUTH_MODE=v2 env var
    // or use of --auth0 switch.
    if (process.env.AUTH_MODE !== 'v2' && !auth0) return Promise.resolve(null);

    var descriptionUrl = Url.parse(sandboxUrl);
    descriptionUrl.pathname = '/api/description';
    return Superagent
        .get(Url.format(descriptionUrl))
        .ok(res => res.status < 500)
        .then(res => {
            if (res.status === 200 && res.body && res.body.authorization_server) {
                return new UserAuthenticator({
                    sandboxUrl,
                    authorizationServer: res.body.authorization_server,
                    audience: res.body.audience || sandboxUrl,
                    clientId: res.body.client_id,
                });
            }
            else {
                return Promise.resolve(null);
            }
        });
};

UserAuthenticator.prototype.login = function (options) {
    options = options || {};

    if (this.refreshToken) {
        return this._refreshFlow(options);<commit_msg>modifed auth mode switch to default to v2<commit_after>var Bluebird = require('bluebird');
var Errors = require('./errors');
var Sandbox = require('sandboxjs');
var Superagent = require('superagent');
var Http = require('http');
var Url = require('url');
var Open = require('opn');
var Chalk = require('chalk');
var Decode = require('jwt-decode');
var Assert = require('assert');
var Crypto = require('crypto');

module.exports = UserAuthenticator;

function UserAuthenticator (config) {
    if (!config) config = {};
    
    this.sandboxUrl = config.sandboxUrl || 'https://sandbox.auth0-extend.com';
    this.authorizationServer = config.authorizationServer;
    this.audience = config.audience;
    this.clientId = config.clientId;
    this.refreshToken = config.refreshToken;
}

// Discover whether WT deployment supports auth v2 and if so create
// UserAuthenticator instance for it
UserAuthenticator.create = function (sandboxUrl, auth0) {
    // TODO, tjanczuk, remove the following line when v2 auth exits beta
    // we are defaulting to AUTHv2 here, we can revert to AUTHv1 using
    // AUTH_MODE=v1 env var
    // the use of --auth0 switch forces AUTHv2 as well.

    if (process.env.AUTH_MODE === 'v1' && !auth0) return Promise.resolve(null);

    var descriptionUrl = Url.parse(sandboxUrl);
    descriptionUrl.pathname = '/api/description';
    return Superagent
        .get(Url.format(descriptionUrl))
        .ok(res => res.status < 500)
        .then(res => {
            if (res.status === 200 && res.body && res.body.authorization_server) {
                return new UserAuthenticator({
                    sandboxUrl,
                    authorizationServer: res.body.authorization_server,
                    audience: res.body.audience || sandboxUrl,
                    clientId: res.body.client_id,
                });
            }
            else {
                return Promise.resolve(null);
            }
        });
};

UserAuthenticator.prototype.login = function (options) {
    options = options || {};

    if (this.refreshToken) {
        return this._refreshFlow(options);
{'fraction_non_alphanumeric': 0.12132883967260472, 'fraction_numerical': 0.0077034183919114105, 'mean_word_length': 2.733153638814016, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '5968806', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1159, 'n_words': 303}