Delphi LDAP and Active Directory Client

Let your users sign in with their Windows domain password. Validate credentials against Active Directory, OpenLDAP or any LDAP v3 directory over an encrypted connection, and read the groups that decide what they can do.

TsgcLDAPClient

An LDAP v3 client built to authenticate users, search the directory and resolve group membership, including nested Active Directory groups.

Component class

TsgcLDAPClient (unit sgcAuth_LDAP_Client)

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Enterprise and All-Access, plus the sgcAuth pack. Also available in sgcWebSockets .NET.

Connect, authenticate, read the groups

Point Host at a domain controller, choose LDAPS or StartTLS, set the service account in BindDN / Password, then call Authenticate with what the user typed.

uses
  sgcAuth_LDAP_Classes, sgcAuth_LDAP_Client;

var
  LDAP: TsgcLDAPClient;
  vUserDN: string;
  oGroups: TStringList;
begin
  LDAP := TsgcLDAPClient.Create(nil);
  LDAP.Host := 'dc01.corp.example.com';
  LDAP.Security := ldapsecLDAPS; // implicit TLS, port 636
  LDAP.BindDN := 'CN=svc-login,OU=Service,DC=corp,DC=example,DC=com';
  LDAP.Password := 'service-password';
  LDAP.BaseDN := 'DC=corp,DC=example,DC=com';
  // find the user with UserSearchFilter, then bind as that DN
  LDAP.AuthenticationMode := ldapamSearchThenBind;
  LDAP.Connect;

  if LDAP.Authenticate(edtUser.Text, edtPassword.Text, vUserDN) then
  begin
    oGroups := TStringList.Create;
    try
      // True: nested groups through LDAP_MATCHING_RULE_IN_CHAIN
      LDAP.GetUserGroups(vUserDN, oGroups, True);
    finally
      oGroups.Free;
    end;
  end
  else
    ShowMessage(LDAP.LastErrorMessage);
end;
// uses: sgcAuth_LDAP_Classes, sgcAuth_LDAP_Client
TsgcLDAPClient *LDAP = new TsgcLDAPClient(this);
LDAP->Host = "dc01.corp.example.com";
LDAP->Security = ldapsecLDAPS;
LDAP->BindDN = "CN=svc-login,OU=Service,DC=corp,DC=example,DC=com";
LDAP->Password = "service-password";
LDAP->BaseDN = "DC=corp,DC=example,DC=com";
LDAP->AuthenticationMode = ldapamSearchThenBind;
LDAP->Connect();

String UserDN;
if (LDAP->Authenticate(edtUser->Text, edtPassword->Text, UserDN))
{
  TStringList *Groups = new TStringList();
  LDAP->GetUserGroups(UserDN, Groups, true);
  delete Groups;
}

What's inside

Directory sign-in for desktop apps, web back ends and services, with the security details handled for you.

LDAPS and StartTLS

Security selects ldapsecLDAPS (implicit TLS on port 636) or ldapsecStartTLS (upgrade on port 389). If the server refuses StartTLS the connection is closed, the client never falls back to clear text. TLSOptions controls certificate verification.

Four sign-in modes

AuthenticationMode turns the typed name into a bind name: ldapamUPN (user@UPNSuffix), ldapamDownLevel (Domain\user), ldapamSearchThenBind (service bind plus UserSearchFilter) or ldapamDN.

Nested groups

GetUserGroups returns the direct memberOf values, or with aNested every group reached through other groups, using the Active Directory rule LDAP_MATCHING_RULE_IN_CHAIN.

Search uses Simple Paged Results automatically (PageSize, 500 by default), honours SizeLimit and TimeLimit, and returns the entries and referrals in a TsgcLDAPEntries list.

Safe binds

Bind refuses a DN with an empty password without contacting the server, closing the unauthenticated bind hole of RFC 4513. WhoAmI, LastResultCode and LastErrorMessage tell you exactly who is bound and why a call failed.

One instance, many threads

Every public method is serialized, so a single TsgcLDAPClient can serve the login requests of a multi-threaded HTTP or WebSocket server.

Specifications & references

Authoritative sources for the standards this component implements.

Documentation & Demos

Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.

Online Help: TsgcLDAPClient Full property, method and event reference for this component.
Demo Project: Demos\26.Authentication\05.LDAP_ActiveDirectory Connect with LDAPS or StartTLS, authenticate in every mode, search and list nested groups. Ships inside the sgcWebSockets package, download the trial below.
Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references for this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.
Blog: Delphi Login With Passkeys, SAML SSO, LDAP and TOTP 2FA How the six authentication components fit together in one Delphi application.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Sign In With Active Directory?

Download the free trial and authenticate your Delphi users against the directory they already have.