fcd275f6c0
refs #9866 - Moved web/middleware to web/shared/middlewares - Moved util file to web/shared/utils
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
const prettyURLs = require('../../shared/middlewares/pretty-urls');
|
|
const cors = require('../../shared/middlewares/api/cors');
|
|
const urlRedirects = require('../../shared/middlewares/url-redirects');
|
|
const auth = require('../../../services/auth');
|
|
|
|
/**
|
|
* Auth Middleware Packages
|
|
*
|
|
* IMPORTANT
|
|
* - cors middleware MUST happen before pretty urls, because otherwise cors header can get lost on redirect
|
|
* - cors middleware MUST happen after authenticateClient, because authenticateClient reads the trusted domains
|
|
* - url redirects MUST happen after cors, otherwise cors header can get lost on redirect
|
|
*/
|
|
|
|
/**
|
|
* Authentication for public endpoints
|
|
*/
|
|
module.exports.authenticatePublic = [
|
|
auth.authenticate.authenticateClient,
|
|
auth.authenticate.authenticateUser,
|
|
// This is a labs-enabled middleware
|
|
auth.authorize.requiresAuthorizedUserPublicAPI,
|
|
cors,
|
|
urlRedirects,
|
|
prettyURLs
|
|
];
|
|
|
|
/**
|
|
* Authentication for private endpoints
|
|
*/
|
|
module.exports.authenticatePrivate = [
|
|
auth.authenticate.authenticateClient,
|
|
auth.authenticate.authenticateUser,
|
|
auth.authorize.requiresAuthorizedUser,
|
|
cors,
|
|
urlRedirects,
|
|
prettyURLs
|
|
];
|
|
|
|
/**
|
|
* Authentication for client endpoints
|
|
*/
|
|
module.exports.authenticateClient = function authenticateClient(client) {
|
|
return [
|
|
auth.authenticate.authenticateClient,
|
|
auth.authenticate.authenticateUser,
|
|
auth.authorize.requiresAuthorizedClient(client),
|
|
cors,
|
|
urlRedirects,
|
|
prettyURLs
|
|
];
|
|
};
|