<commit_before>'use strict';

const boom = require('boom');
const config = require('config');
const casCookieUtils = require('../../utils/cas-cookie-utils.js');
const joi = require('joi');
const _ = require('lodash');

const baseUrl = '/keys';

exports.register = function(server, options, next) {
    // Private route to get new hawk credentials
    // Requests must authenticate with a username and password
    const redisClient =  server.plugins['hapi-redis'].client;
    const authUtils = server.plugins.utilities.auth;
    const invalidCookie = casCookieUtils.invalidate();

    server.state(config.get('casCookieName'), {
        path: '/',
        domain: config.get('cookieDomain')
    });

    server.route({
        method: 'POST',
        path: baseUrl,
        config: {
            tags: ['api', 'auth'],
            notes: [
                'Expects base64 encoded username/password in payload.',
                'Response includes a `set-cookie` header with JWT for COINS2.0'
            ].join('<br>'),
            description: 'Login: Get new API key and JWT cookie',
            auth: false,
            validate: {
                headers: true, //TODO: validate x-forwaded https header
                payload: {
                    username: joi.binary().encoding('base64').required(),
                    password: joi.binary().encoding('base64').required()
                }
            },
            handler: function(request, reply) {<commit_msg>add credentials header to CORS<commit_after>'use strict';

const boom = require('boom');
const config = require('config');
const casCookieUtils = require('../../utils/cas-cookie-utils.js');
const joi = require('joi');
const _ = require('lodash');

const baseUrl = '/keys';

exports.register = function(server, options, next) {
    // Private route to get new hawk credentials
    // Requests must authenticate with a username and password
    const redisClient =  server.plugins['hapi-redis'].client;
    const authUtils = server.plugins.utilities.auth;
    const invalidCookie = casCookieUtils.invalidate();

    server.state(config.get('casCookieName'), {
        path: '/',
        domain: config.get('cookieDomain')
    });

    server.route({
        method: 'POST',
        path: baseUrl,
        config: {
            tags: ['api', 'auth'],
            notes: [
                'Expects base64 encoded username/password in payload.',
                'Response includes a `set-cookie` header with JWT for COINS2.0'
            ].join('<br>'),
            description: 'Login: Get new API key and JWT cookie',
            auth: false,
            cors: {
                credentials: true
            },
            validate: {
                headers: true, //TODO: validate x-forwaded https header
                payload: {
                    username: joi.binary().encoding('base64').required(),
                    password: <PASSWORD>.binary().encoding('base64').required()
                }
            },
            handler: function(request, reply) {
{'fraction_non_alphanumeric': 0.13129318854886476, 'fraction_numerical': 0.0052648897663705166, 'mean_word_length': 2.1147540983606556, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '7528509', 'n_tokens_mistral': 812, 'n_tokens_neox': 783, 'n_words': 215}