mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-16 05:00:02 -04:00
Fixed Cookie Auth
This commit is contained in:
parent
0c1a73e3dc
commit
1c03f77f13
2 changed files with 4 additions and 18 deletions
2
app.js
2
app.js
|
@ -65,8 +65,6 @@
|
||||||
saveUninitialized: true,
|
saveUninitialized: true,
|
||||||
resave: true
|
resave: true
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
// We made our own version of body-parser instead, due to issues.
|
// We made our own version of body-parser instead, due to issues.
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
if (req.method == 'POST') {
|
if (req.method == 'POST') {
|
||||||
|
|
20
auth.js
20
auth.js
|
@ -1,11 +1,6 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
const express = require('express'),
|
var crypto = require('crypto');
|
||||||
app = express(),
|
|
||||||
session = require('express-session'),
|
|
||||||
|
|
||||||
|
|
||||||
var crypto = require('crypto');
|
|
||||||
var os = require('os');
|
var os = require('os');
|
||||||
var querystring = require('querystring');
|
var querystring = require('querystring');
|
||||||
var url = require('url');
|
var url = require('url');
|
||||||
|
@ -24,19 +19,12 @@ module.exports = function(env) {
|
||||||
return module.exports;
|
return module.exports;
|
||||||
};
|
};
|
||||||
|
|
||||||
app.use(session({
|
|
||||||
secret: 'nu_auth',
|
|
||||||
cookie: { sameSite: 'none', secure: 'true' },
|
|
||||||
saveUninitialized: true,
|
|
||||||
resave: true
|
|
||||||
}));
|
|
||||||
|
|
||||||
module.exports.auth = function(req, res, next) {
|
module.exports.auth = function(req, res, next) {
|
||||||
// Allow using with express as well as socket.io
|
// Allow using with express as well as socket.io
|
||||||
next = next || res;
|
next = next || res;
|
||||||
var cookies = new Cookies(req);
|
var cookies = new Cookies(req);
|
||||||
var hash = cookies.get('nu_auth') ?
|
var hash = cookies.get('session') ?
|
||||||
module.exports.hash(cookies.get('nu_auth')) : '';
|
module.exports.hash(cookies.get('session')) : '';
|
||||||
if (settings.hashes.indexOf(hash) >= 0) {
|
if (settings.hashes.indexOf(hash) >= 0) {
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
|
@ -47,7 +35,7 @@ module.exports.auth = function(req, res, next) {
|
||||||
module.exports.sign = function(req, res, next) {
|
module.exports.sign = function(req, res, next) {
|
||||||
var cookies = new Cookies(req, res);
|
var cookies = new Cookies(req, res);
|
||||||
var query = url.parse(req.url, true).query;
|
var query = url.parse(req.url, true).query;
|
||||||
cookies.set('nu_auth', query.key ? module.exports.hash(query.key) : null);
|
cookies.set('session', query.key ? module.exports.hash(query.key) : null);
|
||||||
res.writeHead(302, { location: query.path ? query.path : settings.redirect });
|
res.writeHead(302, { location: query.path ? query.path : settings.redirect });
|
||||||
res.end();
|
res.end();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue