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'; ...@@ -19,16 +19,16 @@ import passport from 'passport';
import LdapStrategy from 'passport-ldapauth'; import LdapStrategy from 'passport-ldapauth';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; 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 // specifies options for 'ldapauth' strategy, to customize the behaviour of subsequent passport.authenticate('ldapauth') calls
passport.use(new LdapStrategy({ passport.use(new LdapStrategy({
server: { server: {
url: config.ldap.server, url: ldapConfig.ldap.server,
//bindDn: '.............', //bindDn: '.............',
//bindCredentials: '..........', //bindCredentials: '..........',
searchBase: config.ldap.searchBase, searchBase: ldapConfig.ldap.searchBase,
searchFilter: config.ldap.searchFilter, searchFilter: ldapConfig.ldap.searchFilter,
//searchAttributes: ['givenName', 'sn'], //searchAttributes: ['givenName', 'sn'],
//tlsOptions: '..........', //tlsOptions: '..........',
}, },
......
...@@ -6,14 +6,18 @@ var fs = require('fs'); ...@@ -6,14 +6,18 @@ var fs = require('fs');
var path = require('path'); var path = require('path');
// Point central ; tous les champs de la BDD sont 'cachés' dans config.json et pas visibles directement // 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 configPath = path.resolve('./', 'ldap_config.json');
const config = JSON.parse(fs.readFileSync(configPath, 'utf8')); 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 // Override config server from environment
if (process.env.LDAP_URI != null) { if (process.env.LDAP_URI != null) {
config.ldap.server = process.env.LDAP_URI; ldapConfig.ldap.server = process.env.LDAP_URI;
} }
module.exports = { module.exports = {
config "ldapConfig": ldapConfig,
"credentialsConfig": credentialsConfig
}; };
This diff is collapsed.
...@@ -32,6 +32,9 @@ import morgan from 'morgan'; ...@@ -32,6 +32,9 @@ import morgan from 'morgan';
import path from 'path'; import path from 'path';
import fs from 'fs'; 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) 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'))); ...@@ -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. * 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 // 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) // 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) // 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...) // 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({ app.use(session({
secret: config.sessionSecret, secret: ldapConfig.sessionSecret,
resave: true, resave: true,
saveUninitialized: false, saveUninitialized: false,
//store: // TODO: change this. express-session doc warns that default value is ok to use for development only //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', ...@@ -203,8 +204,6 @@ app.post('/login',
/** /**
* @desc API GRAPHQL * @desc API GRAPHQL
*/ */
import { dn, passwd } from "../ldap_connexion_config.json"; // default bind user
const environment = process.env.NODE_ENV || 'development'; const environment = process.env.NODE_ENV || 'development';
app.use('/graphql', 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