<commit_before>var router = require('express').Router();
var four0four = require('./utils/404')();
var data = require('./data');
var request = require('request');
var crypto = require('crypto');
var cookiee = require('cookie-encryption');
var vault = cookiee(process.env.APP_KEY, {
    cipher: 'aes-256-cbc',
    encoding: 'base64',
    cookie: 'oauth-secrets',
    httpOnly: true,
});

router.post('/auth', postAuth);
router.get('/me', getMe);
router.get('/*', four0four.notFoundMiddleware);

module.exports = router;

//////////////

function postAuth(req, res, next) {
    var form = {
        grant_type: 'password',
        client_id: process.env.PONIVERSE_CLIENT_ID,
        client_secret: process.env.PONIVERSE_CLIENT_SECRET,
        username: req.body.username,
        password: <PASSWORD>,
        scope: 'basic'
    };

    request.post({
        url: process.env.PONIVERSE_API_URL + '/oauth/access_token',
        form: form
    }, function(error, response, body) {
        if (response.statusCode === 401) {
            return res.status(response.statusCode).send(body);
        }

        var cipher = crypto.createCipher('aes-256-cbc', process.env.APP_KEY);
        var crypted = cipher.update(body,'utf8','base64');
        crypted += cipher.final('base64');

        res.cookie('oauth-secrets', crypted, {maxAge: 900000, httpOnly: true});

        var oauth = JSON.parse(body);

        var authResponse = {
            token: oauth.access_token
        };

        res.status(response.statusCode).send(authResponse);
    });
}

function getMe(req, res, next) {
    var body = vault.read(req);

    if (! body) {
        res.status(401).send();
    }

    var oauth = JSON.parse(body);

    var response = {
        token: oauth.access_token
    };

    res.status(200).send(response);
}
<commit_msg>Add encryption credit<commit_after>var router = require('express').Router();
var four0four = require('./utils/404')();
var data = require('./data');
var request = require('request');
var crypto = require('crypto');
var cookiee = require('cookie-encryption');
var vault = cookiee(process.env.APP_KEY, {
    cipher: 'aes-256-cbc',
    encoding: 'base64',
    cookie: 'oauth-secrets',
    httpOnly: true,
});

router.post('/auth', postAuth);
router.get('/me', getMe);
router.get('/*', four0four.notFoundMiddleware);

module.exports = router;

//////////////

function postAuth(req, res, next) {
    var form = {
        grant_type: 'password',
        client_id: process.env.PONIVERSE_CLIENT_ID,
        client_secret: process.env.PONIVERSE_CLIENT_SECRET,
        username: req.body.username,
        password: <PASSWORD>,
        scope: 'basic'
    };

    request.post({
        url: process.env.PONIVERSE_API_URL + '/oauth/access_token',
        form: form
    }, function(error, response, body) {
        if (response.statusCode === 401) {
            return res.status(response.statusCode).send(body);
        }

        // Credit: http://lollyrock.com/articles/nodejs-encryption/
        var cipher = crypto.createCipher('aes-256-cbc', process.env.APP_KEY);
        var crypted = cipher.update(body,'utf8','base64');
        crypted += cipher.final('base64');

        res.cookie('oauth-secrets', crypted, {maxAge: 900000, httpOnly: true});

        var oauth = JSON.parse(body);

        var authResponse = {
            token: oauth.access_token
        };

        res.status(response.statusCode).send(authResponse);
    });
}

function getMe(req, res, next) {
    var body = vault.read(req);

    if (! body) {
        res.status(401).send();
    }

    var oauth = JSON.parse(body);

    var response = {
        token: oauth.access_token
    };

    res.status(200).send(response);
}

{'fraction_non_alphanumeric': 0.16253369272237198, 'fraction_numerical': 0.01778975741239892, 'mean_word_length': 2.752275025278059, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '728595', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1169, 'n_words': 224}