Skip to content
Snippets Groups Projects
Commit 515c6202 authored by Wilson JALLET's avatar Wilson JALLET :money_with_wings:
Browse files

I tried

parent 82a2a7b8
No related branches found
No related tags found
No related merge requests found
...@@ -108,18 +108,19 @@ router.post('/login', (req, res, next) => { ...@@ -108,18 +108,19 @@ router.post('/login', (req, res, next) => {
else if (!user) { else if (!user) {
return res.json(403, {message: "Not authenticated."}); return res.json(403, {message: "Not authenticated."});
} }
console.log(req.headers); // return 'Origin' header, useful later
req.login(user, (err) => { req.login(user, (err) => {
if (err) { if (err) {
console.log(err); console.log(err);
return err; return err;
} }
// if request asks for a json, reply with a token // if request asks for a json, reply with a token
// else redirect to admin panel // else redirect to admin panel
(req.header('accept') == 'application/json') (req.header('accept') == 'application/json')
? res.json({ message: 'Authentication succeeded.' }) ? res.json({
message: 'Authentication succeeded.'
})
: res.redirect('/admin'); : res.redirect('/admin');
}); });
......
...@@ -75,12 +75,36 @@ const corsOptions = { ...@@ -75,12 +75,36 @@ const corsOptions = {
}; };
server.use(cors(corsOptions)); server.use(cors(corsOptions));
import jwt from 'jsonwebtoken';
const SECRET_KEY = "azojgc;aegpfrihzcksdlmpqsqkx";
/*
const addUser = async (req, res, next) => {
const token = req.cookies.csrftoken;
if (!token) return next();
console.log(`Token is ${token}`);
try {
const { user } = jwt.verify(token, SECRET_KEY);
req.user = user;
} catch (err) {
console.log('Cookie error',err);
}
};
server.use(addUser);
*/
server.use('/graphql', server.use('/graphql',
bodyParser.json(), // parse incoming HTTP request (req) as a JSON bodyParser.json(), // parse incoming HTTP request (req) as a JSON
graphqlHTTP(async (req, res, params) => { graphqlHTTP(async (req, res, params) => {
// vary the options *on a per-request basis* // vary the options *on a per-request basis*
let uid; let uid;
let password; let password;
console.log(`User ${req.user ? req.user.uid : "none"}`);
console.log("User authenticated:",req.isAuthenticated());
if(req.isAuthenticated()) { if(req.isAuthenticated()) {
try { try {
...@@ -95,7 +119,8 @@ server.use('/graphql', ...@@ -95,7 +119,8 @@ server.use('/graphql',
uid = defaultUser.dn.split("=")[1].split(",")[0]; uid = defaultUser.dn.split("=")[1].split(",")[0];
password = defaultUser.passwd; password = defaultUser.passwd;
} }
// console.log("Accessing GraphQL as: ",uid);
console.log("Cookies:",req.cookies);
return { return {
schema, schema,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment