isundil 1 місяць тому
батько
коміт
9e4197fd7b

+ 1 - 0
dist/ldapAuthenticationHandler.d.ts

@@ -9,6 +9,7 @@ export interface LdapAuthenticationConfiguration {
 export declare class LdapAuthenticationHandler implements IAuthenticationHandler {
     private configuration;
     constructor(configuration: LdapAuthenticationConfiguration);
+    private fieldToString;
     private tryBind;
     tryLogin(username: string, password: string, totp?: string): Promise<boolean | null>;
     needTotp(username: string, password: string): Promise<boolean | null>;

+ 1 - 1
dist/ldapAuthenticationHandler.d.ts.map

@@ -1 +1 @@
-{"version":3,"file":"ldapAuthenticationHandler.d.ts","sourceRoot":"","sources":["../src/ldapAuthenticationHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD,MAAM,WAAW,+BAA+B;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,GAAC,IAAI,CAAC;CAC3B;AAOD,qBAAa,yBAA0B,YAAW,sBAAsB;IACpE,OAAO,CAAC,aAAa,CAAkC;gBAEpC,aAAa,EAAE,+BAA+B;YAInD,OAAO;IAyCR,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAMpF,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;CAMrF"}
+{"version":3,"file":"ldapAuthenticationHandler.d.ts","sourceRoot":"","sources":["../src/ldapAuthenticationHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD,MAAM,WAAW,+BAA+B;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,GAAC,IAAI,CAAC;CAC3B;AAOD,qBAAa,yBAA0B,YAAW,sBAAsB;IACpE,OAAO,CAAC,aAAa,CAAkC;gBAEpC,aAAa,EAAE,+BAA+B;IAIjE,OAAO,CAAC,aAAa;YAQP,OAAO;IAqCR,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAMpF,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;CAMrF"}

+ 11 - 8
dist/ldapAuthenticationHandler.js

@@ -5,6 +5,13 @@ export class LdapAuthenticationHandler {
     constructor(configuration) {
         this.configuration = configuration;
     }
+    fieldToString(data) {
+        if (typeof data === "string")
+            return data;
+        if (Array.isArray(data))
+            return this.fieldToString(data[0]);
+        return data.toString("utf8");
+    }
     async tryBind(username, password) {
         if (!username || !password)
             return null;
@@ -19,17 +26,13 @@ export class LdapAuthenticationHandler {
         });
         const bindDn = `${this.configuration.bindDnField}=${username},${this.configuration.bindBase}`;
         let totp = null;
+        let finalUsername = null;
         try {
             await client.bind(bindDn, password);
             if (this.configuration.totpField) {
                 const data = await client.search(bindDn);
-                let totpData = data.searchEntries[0]?.[this.configuration.totpField];
-                if (typeof totpData === "string")
-                    totp = totpData;
-                if (Array.isArray(totpData))
-                    totp = totpData.join("");
-                else
-                    totp = totpData.toString("utf8");
+                totp = this.fieldToString(data.searchEntries[0]?.[this.configuration.totpField]);
+                finalUsername = this.fieldToString(data.searchEntries[0]?.[this.configuration.usernameField]);
             }
         }
         catch (ex) {
@@ -40,7 +43,7 @@ export class LdapAuthenticationHandler {
             client.unbind();
         }
         return {
-            username: username,
+            username: finalUsername,
             totp: totp
         };
     }

Різницю між файлами не показано, бо вона завелика
+ 0 - 1
dist/ldapAuthenticationHandler.js.map


+ 12 - 8
src/ldapAuthenticationHandler.ts

@@ -22,6 +22,14 @@ export class LdapAuthenticationHandler implements IAuthenticationHandler {
         this.configuration = configuration;
     }
 
+    private fieldToString(data: string|string[]|Buffer|Buffer[]): string {
+        if (typeof data === "string")
+            return data;
+        if (Array.isArray(data))
+            return this.fieldToString(data[0]);
+        return data.toString("utf8");
+    }
+
     private async tryBind(username: string, password: string): Promise<AccountInformations|null> {
         if (!username || !password)
             return null;
@@ -36,18 +44,14 @@ export class LdapAuthenticationHandler implements IAuthenticationHandler {
         });
         const bindDn = `${this.configuration.bindDnField}=${username},${this.configuration.bindBase}`;
         let totp: string|null = null;
+        let finalUsername: string|null = null;
 
         try {
             await client.bind(bindDn, password);
             if (this.configuration.totpField) {
                 const data = await client.search(bindDn);
-                let totpData = data.searchEntries[0]?.[this.configuration.totpField];
-                if (typeof totpData === "string")
-                    totp = totpData;
-                if (Array.isArray(totpData))
-                    totp = totpData.join("");
-                else
-                    totp = totpData.toString("utf8");
+                totp = this.fieldToString(data.searchEntries[0]?.[this.configuration.totpField]);
+                finalUsername = this.fieldToString(data.searchEntries[0]?.[this.configuration.usernameField]);
             }
         }
         catch (ex) {
@@ -58,7 +62,7 @@ export class LdapAuthenticationHandler implements IAuthenticationHandler {
             client.unbind();
         }
         return <AccountInformations> {
-            username: username,
+            username: finalUsername,
             totp: totp
         };
     }

Деякі файли не було показано, через те що забагато файлів було змінено