mirror of
https://github.com/Ride-The-Lightning/RTL.git
synced 2024-11-19 09:50:36 +01:00
Regenerating fresh cookie
Regenerating fresh cookie
This commit is contained in:
parent
65209239e8
commit
0ca3ed99b3
17
connect.js
17
connect.js
@ -204,7 +204,7 @@ const setSSOParams = (config) => {
|
||||
} else {
|
||||
common.rtl_cookie_path = common.rtl_conf_file_path + '/cookies/auth.cookie';
|
||||
}
|
||||
readCookie(common.rtl_cookie_path);
|
||||
connect.readCookie(common.rtl_cookie_path);
|
||||
}
|
||||
};
|
||||
|
||||
@ -221,7 +221,7 @@ const createDirectory = (dirname) => {
|
||||
}
|
||||
}
|
||||
|
||||
const readCookie = (cookieFile) => {
|
||||
connect.readCookie = (cookieFile) => {
|
||||
let exists = fs.existsSync(cookieFile);
|
||||
if (exists) {
|
||||
common.cookie = fs.readFileSync(cookieFile, 'utf-8');
|
||||
@ -239,6 +239,17 @@ const readCookie = (cookieFile) => {
|
||||
}
|
||||
}
|
||||
|
||||
connect.refreshCookie = (cookieFile) => {
|
||||
try {
|
||||
fs.writeFileSync(cookieFile, crypto.randomBytes(64).toString('hex'));
|
||||
common.cookie = fs.readFileSync(cookieFile, 'utf-8');
|
||||
}
|
||||
catch(err) {
|
||||
console.error('Something went wrong while refreshing cookie: \n' + err);
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
String.random = function (length) {
|
||||
let radom13chars = function () {
|
||||
return Math.random().toString(16).substring(2, 15).toUpperCase();
|
||||
@ -290,4 +301,4 @@ connect.configFileExists = () => {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = connect.configFileExists();
|
||||
module.exports = connect;
|
||||
|
@ -1,6 +1,7 @@
|
||||
var ini = require('ini');
|
||||
var fs = require('fs');
|
||||
var common = require('../common');
|
||||
var connect = require('../connect');
|
||||
const jwt = require("jsonwebtoken");
|
||||
var upperCase = require('upper-case');
|
||||
var atob = require('atob');
|
||||
@ -32,6 +33,7 @@ exports.authenticateUser = (req, res, next) => {
|
||||
// Replace access_key value from req.cookies['access-key'] to req.body.password to test SSO on http
|
||||
// const access_key = atob(req.body.password);
|
||||
if (common.cookie === access_key) {
|
||||
connect.refreshCookie(common.rtl_cookie_path);
|
||||
const token = jwt.sign(
|
||||
{ user: 'Custom_User', lndConfigPath: common.lnd_config_path, macaroonPath: common.macaroon_path },
|
||||
common.secret_key
|
||||
|
2
rtl.js
2
rtl.js
@ -2,7 +2,7 @@ const app = require("./app");
|
||||
const common = require("./common");
|
||||
const debug = require("debug")("node-angular");
|
||||
const http = require("http");
|
||||
var connect = require('./connect'); //Do NOT Remove
|
||||
var connect = require('./connect').configFileExists(); //Do NOT Remove
|
||||
|
||||
const onError = error => {
|
||||
if (error.syscall !== "listen") {
|
||||
|
Loading…
Reference in New Issue
Block a user