Update LDAP auth

This commit is contained in:
asyncnomi 2022-12-11 18:19:45 +01:00
parent f9e1bca005
commit bd5b5b224d
2 changed files with 15 additions and 12 deletions

View file

@ -2,6 +2,7 @@ const fastify = require('fastify')({ logger: true })
const fs = require('fs');
const path = require('path')
var LdapAuth = require('ldapauth-fork');
let prompt = require('password-prompt')
var prankPath = "prankdata.txt";
if (!fs.existsSync(prankPath)) {
@ -13,17 +14,7 @@ let AdminUsersUid = ["asyncnomi", "johan", "enthalpine", "fas", "arina", "billy"
let UsersToken = {};
let TokenDurationSecond = 3600;
var LDAP = new LdapAuth({
url: 'ldap://10.5.0.44',
bindDN: 'cn=zammad,ou=service-users,dc=ldap,dc=rezo-rm,dc=fr',
bindCredentials: 'fenfkjnelnfcsqzjkBZKBDZKclZJdzm',
searchBase: 'dc=ldap,dc=rezo-rm,dc=fr',
searchFilter: '(uid={{username}})',
reconnect: true,
});
LDAP.on('error', function (err) {
console.error('LdapAuth: ', err);
});
var LDAP;
fastify.addContentTypeParser('application/json', {
parseAs: 'string'
@ -351,6 +342,17 @@ function makeid(length) {
const start = async () => {
try {
LDAP = new LdapAuth({
url: 'ldap://10.5.0.44',
bindDN: 'cn='+ await prompt("LDAP Bind User: ") +',ou=service-users,dc=ldap,dc=rezo-rm,dc=fr',
bindCredentials: await prompt("LDAP Bind Password: "),
searchBase: 'dc=ldap,dc=rezo-rm,dc=fr',
searchFilter: '(uid={{username}})',
reconnect: true,
});
LDAP.on('error', function (err) {
console.error('LdapAuth: ', err);
});
await fastify.listen({ port: 3000 , host: '127.0.0.1',})
} catch (err) {
fastify.log.error(err)

View file

@ -11,6 +11,7 @@
"dependencies": {
"@fastify/static": "^6.6.0",
"fastify": "^4.10.2",
"ldapauth-fork": "^5.0.5"
"ldapauth-fork": "^5.0.5",
"password-prompt": "^1.1.2"
}
}