diff --git a/src/libs/routes/enrollment.js b/src/libs/routes/enrollment.js
index 9076cdadbdeb0b20d008175d57db17dd6aa719e6..3ab46ca9df12fdfd36c79321cfa43c18a2739696 100644
--- a/src/libs/routes/enrollment.js
+++ b/src/libs/routes/enrollment.js
@@ -18,7 +18,9 @@ const id2str = require(`${libs}/middlewares/id2str`);
 
 const config = require(`${libs}/config`); 
 
-const request = require(`request`);
+const passport = require('passport');
+
+const download = require(`${libs}/middlewares/downloadDatabase`);
 
 const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
 
@@ -481,42 +483,6 @@ simRqf.addField({
     }
 });
 
-enrollmentApp.get('/download', (req, res, next) => {
-    // first, query the mapping
-    req.sql.from('mapping_matricula')
-    .field('target_name')
-    .field('name');
-next();
-}, query, (req, res, next) => {
-    req.resetSql();
-    next();
-}, rqf.parse(), rqf.build(), (req, res, next) => {
-    let username = req.query.user;
-    let email = req.query.email;
-
-    req.sql.from('matricula')
-    .field('*');
-    let header = '';
-    req.result.forEach((result) => {
-        if(header === '') header += result.name;
-        else header = header + ';' + result.name;
-    });
-
-    let form = {
-        query: req.sql.toString(),
-        table: req.sql.tableFrom,
-        name: req.sql.tableFrom,
-        username,
-        email,
-        header
-    };
-    request.post(config.cdn.url + '/api/v1/file', {form}, (err, response, body) => {
-        if(err) {
-            log.error(err);
-            return res.json({error: err});
-        }
-        res.json({msg: 'Wait for download email'});
-    });
-});
+enrollmentApp.get('/download', passport.authenticate('bearer', { session: false }), rqf.parse(), rqf.build(), download('matricula', 'mapping_matricula'));
 
 module.exports = enrollmentApp;