<commit_before>'use strict';

var superagent = require('superagent'),
    winston = require('winston'),
    logger = winston.loggers.get('authentication');

/**
 * Server-side implementation of Oauth-2
 * {
 *   # server url that validates the token and returns json with userdata
 *   server: "http://example.com/user"
 * }
 */
function OAUTH2(settings) {
    this.settings = settings;
}

OAUTH2.prototype.name = 'OAUTH2';

OAUTH2.prototype.match = function (method) {
    if (method === 'X-OAUTH2') {
        return true;
    }
    return false;
};

OAUTH2.prototype.authenticate = function (opts, cb) {
    logger.info("OAUTH2 authenticate ", opts.oauth_token);

    // load user details
    superagent
        .post(this.settings.server)
        .send({})
        .set('content-type', "application/json")
        .set('Authorization', "Bearer " + opts.oauth_token)
        .end(function (error, res) {
            if (error) {
                cb(error);
            } else {

                // TODO check login with user in jid
                // verify the username from json with requested username
                // console.log(res.body.login);

                var user = opts;
                user.email = res.body.login;

                // TODO merge properties properly
                console.log(JSON.stringify(opts.jid));
                cb(null, user);
            }
        });<commit_msg>externalize oauth token handling because this differs for each implementation<commit_after>'use strict';

var winston = require('winston'),
    logger = winston.loggers.get('authentication');

/**
 * Server-side implementation of Oauth-2
 */
function OAUTH2(handler, settings) {
    this.settings = settings;
    this.handler = handler ||   function (settings, opts, cb) {
        cb('Authentication not possible');
    };
}

OAUTH2.prototype.name = 'OAUTH2';

OAUTH2.prototype.match = function (method) {
    if (method === 'X-OAUTH2') {
        return true;
    }
    return false;
};

OAUTH2.prototype.authenticate = function (opts, cb) {
    logger.info("OAUTH2 authenticate ", opts.oauth_token);
    this.handler(this.settings, opts, cb);
{'fraction_non_alphanumeric': 0.1301720130172013, 'fraction_numerical': 0.007438400743840074, 'mean_word_length': 2.3996840442338074, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '2523136', 'n_tokens_mistral': 642, 'n_tokens_neox': 620, 'n_words': 151}