Skip to content

Commit

Permalink
fix(ldap.ts): default auth function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
simonecorsi committed Nov 22, 2022
1 parent 1213319 commit 9b7c25a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/ldap-auth-backend/src/ldap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,20 @@ export async function defaultLDAPAuthentication(
ldapAuthOptions: AuthenticationOptions,
authFunction: typeof authenticate = authenticate
): Promise<LDAPUser> {
const { usernameAttribute, userSearchBase } = ldapAuthOptions;
const usernameAttribute = ldapAuthOptions.usernameAttribute || 'uid';

const userDn =
dn`${usernameAttribute as string}=${username as string},` +
ldapAuthOptions.userSearchBase;

const authObj = {
...ldapAuthOptions,
username,
usernameAttribute,
userDn,
userPassword: password,
userDn:
dn`${usernameAttribute as string}=${username as string},` +
userSearchBase,
};

const user = await authFunction(authObj);
if (!user[usernameAttribute as string]) {
throw new Error(AUTH_USER_NOT_FOUND);
Expand Down

0 comments on commit 9b7c25a

Please sign in to comment.