mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-01 20:41:29 +03:00
Added additional info when requests are rejected due to no auth
Added two additional auth methods: registering and logging in. They have minimal functionality right now Added auth module which will handle all auth-related requests
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
var async = require('async');
|
||||
const { uuid } = require('uuidv4');
|
||||
var fs = require('fs-extra');
|
||||
var auth = require('./authentication/auth');
|
||||
var winston = require('winston');
|
||||
var path = require('path');
|
||||
var youtubedl = require('youtube-dl');
|
||||
@@ -146,6 +147,9 @@ var descriptors = {};
|
||||
app.use(bodyParser.urlencoded({ extended: false }));
|
||||
app.use(bodyParser.json());
|
||||
|
||||
// use passport
|
||||
app.use(auth.passport.initialize());
|
||||
|
||||
// objects
|
||||
|
||||
function File(id, title, thumbnailURL, isAudio, duration, url, uploader, size, path, upload_date) {
|
||||
@@ -1253,6 +1257,7 @@ app.use(function(req, res, next) {
|
||||
} else if (req.path.includes('/api/video/') || req.path.includes('/api/audio/')) {
|
||||
next();
|
||||
} else {
|
||||
logger.verbose(`Rejecting request - invalid API use for endpoint: ${req.path}. API key received: ${req.query.apiKey}`);
|
||||
req.socket.end();
|
||||
}
|
||||
});
|
||||
@@ -2303,6 +2308,17 @@ app.get('/api/audio/:id', function(req , res){
|
||||
})
|
||||
});
|
||||
|
||||
// user authentication
|
||||
|
||||
app.post('/api/auth/register'
|
||||
, auth.registerUser);
|
||||
app.post('/api/auth/login'
|
||||
// , auth.passport.authenticate('basic',{session:false}) // causes challenge pop-up on 401
|
||||
, auth.authenticateViaPassport
|
||||
, auth.generateJWT
|
||||
, auth.returnAuthResponse
|
||||
);
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
//if the request is not html then move along
|
||||
var accept = req.accepts('html', 'json', 'xml');
|
||||
|
||||
Reference in New Issue
Block a user