{"size": 811, "ext": "js", "max_stars_repo_path": "lib/authtoken.js", "max_stars_repo_name": "hapijs/university", "max_stars_repo_stars_event_min_datetime": "2015-05-20T22:52:10.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-06T05:49:25.000Z", "max_issues_repo_path": "lib/authtoken.js", "max_issues_repo_name": "outmoded/university", "max_issues_repo_issues_event_min_datetime": "2015-05-20T20:19:33.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-07T22:35:47.000Z", "max_forks_repo_path": "lib/authtoken.js", "max_forks_repo_name": "outmoded/university", "max_forks_repo_forks_event_min_datetime": "2015-05-22T19:27:14.000Z", "max_forks_repo_forks_event_max_datetime": "2018-09-08T11:01:40.000Z"}
{"max_stars_count": 272, "max_issues_count": 84, "max_forks_count": 200, "avg_line_length": 22.5277777778, "max_line_length": 69, "alphanum_fraction": 0.6288532676}
'use strict';


// Declare internals

const internals = {};

const defaultValidateFunc = async (request, token) => {

    // catbox-redis cache used to confirm if token is valid.
    // * [catbox-redis](https://github.com/hapijs/catbox-redis)
    // * [catbox](https://github.com/hapijs/catbox)

    const authtoken = await request.server.app.authtokens.get(token);

    return {
        isValid: authtoken.value !== null,
        credentials: authtoken.value
    };
};

exports.plugin = {
    name: 'authtoken',
    version: '1.0.0',
    description: 'register hapi-auth-bearer-token strategy.',
    register: function (server, options) {

        server.auth.strategy('default', 'bearer-access-token', {
            validate: defaultValidateFunc
        });

        server.auth.default('default');
    }
};

