Skip to content

Commit

Permalink
feat: add optional function for LDAPBasicAuthIdentityProvider to prov…
Browse files Browse the repository at this point in the history
…ide different userid in case it differs from dn
  • Loading branch information
Tethik committed Oct 4, 2023
1 parent 3415160 commit b94bb7f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions plugins/ldap/src/LDAPBasicAuthIdentityProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ export class LDAPBasicAuthIdentityProvider implements IdentityProvider {

/**
*
* @param DNforUsername should be a function that formats a username into a DN for use in an LDAP bind.
* @param DNForUsername should be a function that formats a username into a DN for use in an LDAP bind.
* e.g. (name) => `uid=${name},ou=Users`;
* @param SubForUsername optional function to map username to a different sub (id). Use this if your user lookup
* uses a different attribute.
*/
constructor(
private ldapSettings: LDAPClientSettings,
private DNforUsername: (username: string) => string
private DNForUsername: (username: string) => string,
private SubForUsername: (username: string) => string = (username) =>
username
) {}

async params(): Promise<IdentityProviderParams> {
Expand All @@ -51,7 +55,7 @@ export class LDAPBasicAuthIdentityProvider implements IdentityProvider {

const ldap = await initLdapClient(this.ldapSettings);

const dn = this.DNforUsername(name);
const dn = this.DNForUsername(name);

try {
await ldap.bind(dn, pass);
Expand All @@ -69,7 +73,7 @@ export class LDAPBasicAuthIdentityProvider implements IdentityProvider {
return {
status: "ok",
identity: {
sub: name,
sub: this.SubForUsername(name),
},
};
}
Expand Down

0 comments on commit b94bb7f

Please sign in to comment.