Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Made an update to the lib/plugin.js example per RDPP-2152 and Gavin's comment

...

Code Block
titlelib/plugin.js
// Constructor to get a reference to the config object
function Plugin(server) {
    this.config = server.config || {secret: null};
}

// Only validate requests to /api/foo
Plugin.prototype.matchURL = function(request) {
    return request.url.indexOf('/api/foo') !== 0;
};

// Check if the request has the X-Secret header and its value matches the config file
Plugin.prototype.validateRequest = function(request, response) {
    if (request.headers['x-secret'] && request.headers['x-secret'] === this.config.secret) {
        return true;
    } else {
        return false;
    }
};

// Add the X-Secret header for internal requests
Plugin.prototype.applyCredentialsForTest = function(options) {
    options.headers['x-secret'] = this.config.secret;
};

// Do not process the response
Plugin.prototype.applyResponseForTest = function(response, body) {
    return body;
};

// Describe the x-security header for the Swagger 2.0 feed
Plugin.prototype.getSwaggerSecurity = function () {
	return {
		securityDefinitions: {
			app_auth: {
				type: 'apiKey',
				name: 'apikeyx-secret',
				in: 'header',
				description: 'Require authorized access to API'
			}
		},
		security: [{
			app_auth: []
		}]
	}
}

module.exports = Plugin;

...