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

refactor remaining ldap config imports

parent 7ef8a65e
No related branches found
No related tags found
No related merge requests found
......@@ -19,16 +19,16 @@ import passport from 'passport';
import LdapStrategy from 'passport-ldapauth';
import fs from 'fs';
import path from 'path';
import { config } from './ldap/config';
import { ldapConfig } from './ldap/config';
// specifies options for 'ldapauth' strategy, to customize the behaviour of subsequent passport.authenticate('ldapauth') calls
passport.use(new LdapStrategy({
server: {
url: config.ldap.server,
url: ldapConfig.ldap.server,
//bindDn: '.............',
//bindCredentials: '..........',
searchBase: config.ldap.searchBase,
searchFilter: config.ldap.searchFilter,
searchBase: ldapConfig.ldap.searchBase,
searchFilter: ldapConfig.ldap.searchFilter,
//searchAttributes: ['givenName', 'sn'],
//tlsOptions: '..........',
},
......
......@@ -6,14 +6,18 @@ var fs = require('fs');
var path = require('path');
// Point central ; tous les champs de la BDD sont 'cachés' dans config.json et pas visibles directement
var configPath = path.resolve('./', 'ldap_config.json');
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
const configPath = path.resolve('./', 'ldap_config.json');
const ldapConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'));
const credentialsPath = path.resolve('./', 'ldap_connexion_config.json');
const credentialsConfig = JSON.parse(fs.readFileSync(credentialsPath));
// Override config server from environment
if (process.env.LDAP_URI != null) {
config.ldap.server = process.env.LDAP_URI;
ldapConfig.ldap.server = process.env.LDAP_URI;
}
module.exports = {
config
"ldapConfig": ldapConfig,
"credentialsConfig": credentialsConfig
};
This diff is collapsed.
......@@ -32,6 +32,9 @@ import morgan from 'morgan';
import path from 'path';
import fs from 'fs';
import { ldapConfig, credentialsConfig } from './ldap/config';
const { dn, passwd } = credentialsConfig;
const app = express(); // "The app object conventionally denotes the Express application" (https://expressjs.com/en/4x/api.html#app)
......@@ -74,15 +77,13 @@ app.use('/assets', express.static(path.resolve('./', 'assets')));
* Remarque: introduit aussi les middlewares session et passport, qui sont aussi utiles pour l'authentification dans les autres cas.
*/
const configPath = path.resolve('./', 'ldap_config.json');
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
// WTF??? why is sessionSecret in ldap_config.json? it has nothing to do with ldap. TODO
// defines parameters for *session store*. (adds field req.session and do some magic stuff)
// basically, searches for a session matching the received cookie and, if found, adds field req.blasomethingbla containing serialized object representing user (i.e. similar to what passport.serializeUser() could produce)
// TODO: it is important to configure this right!!! please check out https://www.npmjs.com/package/express-session and make sure you understand the way session is stored. (en vrai c'est vraiment important...)
app.use(session({
secret: config.sessionSecret,
secret: ldapConfig.sessionSecret,
resave: true,
saveUninitialized: false,
//store: // TODO: change this. express-session doc warns that default value is ok to use for development only
......@@ -203,8 +204,6 @@ app.post('/login',
/**
* @desc API GRAPHQL
*/
import { dn, passwd } from "../ldap_connexion_config.json"; // default bind user
const environment = process.env.NODE_ENV || 'development';
app.use('/graphql',
......
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