Commit a3ab3933 authored by simon's avatar simon

fix(google-auth): search base must include ou

parent f4deaecc
...@@ -14,6 +14,7 @@ interface IGoogleLDAPAuthOptions { ...@@ -14,6 +14,7 @@ interface IGoogleLDAPAuthOptions {
/** base DN /** base DN
* e.g. 'dc=hokify,dc=com', */ * e.g. 'dc=hokify,dc=com', */
base: string; base: string;
searchBase?: string; // default ou=users,{{base}}
tls: { tls: {
keyFile: string; keyFile: string;
certFile: string; certFile: string;
...@@ -35,8 +36,11 @@ export class GoogleLDAPAuth implements IAuthentication { ...@@ -35,8 +36,11 @@ export class GoogleLDAPAuth implements IAuthentication {
private config: ClientOptions; private config: ClientOptions;
searchBase: string;
constructor(config: IGoogleLDAPAuthOptions) { constructor(config: IGoogleLDAPAuthOptions) {
this.base = config.base; this.base = config.base;
this.searchBase = config.searchBase || `ou=users,${this.base}`;
const tlsOptions = { const tlsOptions = {
key: fs.readFileSync(config.tls.keyFile), key: fs.readFileSync(config.tls.keyFile),
...@@ -50,7 +54,9 @@ export class GoogleLDAPAuth implements IAuthentication { ...@@ -50,7 +54,9 @@ export class GoogleLDAPAuth implements IAuthentication {
tlsOptions, tlsOptions,
}; };
this.fetchDNs(); this.fetchDNs().catch((err) => {
console.error('fatal error google ldap auth, cannot fetch DNs', err);
});
} }
private async fetchDNs() { private async fetchDNs() {
...@@ -63,7 +69,7 @@ export class GoogleLDAPAuth implements IAuthentication { ...@@ -63,7 +69,7 @@ export class GoogleLDAPAuth implements IAuthentication {
}); });
ldapDNClient.search( ldapDNClient.search(
this.base, this.searchBase,
{ {
scope: 'sub', scope: 'sub',
}, },
...@@ -87,7 +93,7 @@ export class GoogleLDAPAuth implements IAuthentication { ...@@ -87,7 +93,7 @@ export class GoogleLDAPAuth implements IAuthentication {
res.on('error', function (ldapErr) { res.on('error', function (ldapErr) {
console.error(`error: ${JSON.stringify(ldapErr)}`); console.error(`error: ${JSON.stringify(ldapErr)}`);
reject(); reject(ldapErr);
}); });
res.on('end', (result) => { res.on('end', (result) => {
...@@ -132,6 +138,7 @@ export class GoogleLDAPAuth implements IAuthentication { ...@@ -132,6 +138,7 @@ export class GoogleLDAPAuth implements IAuthentication {
if (!dnsFetched && !forceFetching) { if (!dnsFetched && !forceFetching) {
return this.authenticate(username, password, count, true); return this.authenticate(username, password, count, true);
} }
// console.log('this.allValidDNsCache', this.allValidDNsCache);
console.error(`invalid username, not found in DN: ${username}`); // , this.allValidDNsCache); console.error(`invalid username, not found in DN: ${username}`); // , this.allValidDNsCache);
return false; return false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment