{"size": 909, "ext": "js", "max_stars_repo_path": "test/fixtures/lib/stub-auth-token-scheme.js", "max_stars_repo_name": "mikiec84/swaggerize-hapi", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/fixtures/lib/stub-auth-token-scheme.js", "max_issues_repo_name": "mikiec84/swaggerize-hapi", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/fixtures/lib/stub-auth-token-scheme.js", "max_forks_repo_name": "mikiec84/swaggerize-hapi", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.7352941176, "max_line_length": 111, "alphanum_fraction": 0.5093509351}
'use strict';

var Boom = require('boom');

exports.register = function (server, options, next) {
    server.auth.scheme('stub-auth-token', function (server, options) {
        var scheme = {
            authenticate: function (request, reply) {
                var token = request.raw.req.headers.authorization;

                if (!token) {
                    return reply(Boom.unauthorized());
                }

                options.validateFunc(token, function (err, isValid, credentials) {
                    if (err || !isValid) {
                        return reply(Boom.unauthorized(null, 'stub-auth-token'), { credentials: credentials });
                    }

                    return reply.continue({ credentials: credentials });
                });
            }
        };

        return scheme;
    });

    next();
};

exports.register.attributes = {
    name: 'stub-auth-token'
};
