2017-08-17 13:52:58 +03:00
|
|
|
var prettyURLs = require('../middleware/pretty-urls'),
|
|
|
|
cors = require('../middleware/api/cors'),
|
2017-09-13 20:24:11 +03:00
|
|
|
urlRedirects = require('../middleware/url-redirects'),
|
2017-12-14 05:01:23 +03:00
|
|
|
auth = require('../../services/auth');
|
2017-08-17 13:52:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Auth Middleware Packages
|
|
|
|
*
|
|
|
|
* IMPORTANT
|
2017-09-13 20:24:11 +03:00
|
|
|
* - cors middleware MUST happen before pretty urls, because otherwise cors header can get lost on redirect
|
2017-08-17 13:52:58 +03:00
|
|
|
* - cors middleware MUST happen after authenticateClient, because authenticateClient reads the trusted domains
|
2017-09-13 20:24:11 +03:00
|
|
|
* - url redirects MUST happen after cors, otherwise cors header can get lost on redirect
|
2017-08-17 13:52:58 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Authentication for public endpoints
|
|
|
|
*/
|
|
|
|
module.exports.authenticatePublic = [
|
|
|
|
auth.authenticate.authenticateClient,
|
|
|
|
auth.authenticate.authenticateUser,
|
|
|
|
// This is a labs-enabled middleware
|
|
|
|
auth.authorize.requiresAuthorizedUserPublicAPI,
|
|
|
|
cors,
|
2017-09-13 20:24:11 +03:00
|
|
|
urlRedirects,
|
2017-08-17 13:52:58 +03:00
|
|
|
prettyURLs
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Authentication for private endpoints
|
|
|
|
*/
|
|
|
|
module.exports.authenticatePrivate = [
|
|
|
|
auth.authenticate.authenticateClient,
|
|
|
|
auth.authenticate.authenticateUser,
|
|
|
|
auth.authorize.requiresAuthorizedUser,
|
|
|
|
cors,
|
2017-09-13 20:24:11 +03:00
|
|
|
urlRedirects,
|
2017-08-17 13:52:58 +03:00
|
|
|
prettyURLs
|
|
|
|
];
|
2017-08-22 13:15:40 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Authentication for client endpoints
|
|
|
|
*/
|
|
|
|
module.exports.authenticateClient = function authenticateClient(client) {
|
|
|
|
return [
|
|
|
|
auth.authenticate.authenticateClient,
|
|
|
|
auth.authenticate.authenticateUser,
|
|
|
|
auth.authorize.requiresAuthorizedClient(client),
|
|
|
|
cors,
|
2017-09-13 20:24:11 +03:00
|
|
|
urlRedirects,
|
2017-08-22 13:15:40 +03:00
|
|
|
prettyURLs
|
|
|
|
];
|
|
|
|
};
|