extrapolated auth skip function
This commit is contained in:
parent
b7fd186d61
commit
f7a6f52b75
2 changed files with 11 additions and 10 deletions
|
@ -2,14 +2,8 @@ const db = require('../models');
|
|||
const logger = require('winston');
|
||||
|
||||
module.exports = {
|
||||
authenticateChannelCredentials (skipAuth, channelName, userPassword) {
|
||||
authenticateChannelCredentials (channelName, userPassword) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// skip authentication if not needed
|
||||
if (skipAuth) {
|
||||
resolve(skipAuth);
|
||||
return;
|
||||
}
|
||||
// authentication
|
||||
const userName = channelName.substring(1);
|
||||
logger.debug(`authenticateChannelCredentials > channelName: ${channelName} username: ${userName} pass: ${userPassword}`);
|
||||
db.User
|
||||
|
|
|
@ -9,6 +9,13 @@ const errorHandlers = require('../helpers/errorHandlers.js');
|
|||
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
|
||||
const { authenticateChannelCredentials } = require('../auth/authentication.js');
|
||||
|
||||
function authenticateOrSkip (skipAuth, channelName, channelPassword) {
|
||||
if (skipAuth) {
|
||||
return true;
|
||||
}
|
||||
return authenticateChannelCredentials(channelName, channelPassword);
|
||||
}
|
||||
|
||||
module.exports = (app) => {
|
||||
// route to run a claim_list request on the daemon
|
||||
app.get('/api/claim_list/:name', ({ headers, ip, originalUrl, params }, res) => {
|
||||
|
@ -126,9 +133,9 @@ module.exports = (app) => {
|
|||
channelName = cleanseChannelName(channelName);
|
||||
logger.debug(`name: ${name}, license: ${license} title: "${title}" description: "${description}" channelName: "${channelName}" channelPassword: "${channelPassword}" nsfw: "${nsfw}"`);
|
||||
// check channel authorization
|
||||
authenticateChannelCredentials(skipAuth, channelName, channelPassword)
|
||||
.then(result => {
|
||||
if (!result) {
|
||||
authenticateOrSkip(skipAuth)
|
||||
.then(authenticated => {
|
||||
if (!authenticated) {
|
||||
throw new Error('Authentication failed, you do not have access to that channel');
|
||||
}
|
||||
// make sure the claim name is available
|
||||
|
|
Loading…
Add table
Reference in a new issue