# LDAP Auth Configuration

The `ldap-auth` plugin verifies HTTP Basic credentials with an LDAP directory and maps the authenticated directory user to an API consumer.<!-- --> <!-- -->Configuration covers credential fields and route and service fields.

## Parameters[​](#parameters "Direct link to Parameters")

See plugin [common configurations](https://docs.api7.ai/apisix/reference/plugin-common-configurations.md) for configuration options available to all plugins.

### Credentials[​](#credentials "Direct link to Credentials")

The following attributes configure LDAP Auth on a [consumer](https://docs.api7.ai/apisix/key-concepts/consumers.md).

* user\_dn

  string

  required

  ***

  Distinguished name of the LDAP entry represented by the consumer, such as `uid=johndoe,ou=users,dc=example,dc=org`. It must match the DN used for the successful directory bind.

  API7 Gateway 3.10.6 and APISIX 3.18.0 introduced RFC 4514 escaping when constructing the bind DN. If the user name contains structural characters, configure `user_dn` with the matching escaped DN. API7 Gateway 3.9 does not escape these characters.

  Supports an environment variable reference with the `$env://` prefix or a secret-manager reference with the `$secret://` prefix. See [environment variables in plugins](https://docs.api7.ai/apisix/reference/environment-variables.md#plugins) and [secrets](https://docs.api7.ai/apisix/key-concepts/secrets.md).

### Routes or Services[​](#routes-or-services "Direct link to Routes or Services")

The following attributes configure LDAP Auth on [routes](https://docs.api7.ai/apisix/key-concepts/routes.md) or [services](https://docs.api7.ai/apisix/key-concepts/services.md).

* base\_dn

  string

  required

  ***

  Base distinguished name appended to the user name when the plugin constructs the bind DN, such as `ou=users,dc=example,dc=org`.

* ldap\_uri

  string

  required

  ***

  LDAP directory address as `host` or `host:port`. The default port is `389` when omitted.

* use\_tls

  boolean

  default: `false`

  ***

  If true, connect to the directory over LDAPS. This field does not enable StartTLS.

* tls\_verify

  boolean

  default: `false`

  ***

  If true, verify the directory certificate when `use_tls` is enabled. Configure the gateway trust bundle so that it trusts the issuing CA and use a directory host name covered by the certificate.

* uid

  string

  default: `cn`

  ***

  LDAP attribute placed before the client-supplied user name when constructing the bind DN. For example, `uid` produces `uid=johndoe,<base_dn>`.

* hide\_credentials

  boolean

  default: `false`

  ***

  If true, remove the `Authorization` header after authentication so the directory password is not forwarded upstream.

  Introduced in API7 Gateway 3.10.6 and APISIX 3.18.0. API7 Gateway 3.9 does not support this field and forwards the header upstream.

* realm

  string

  default: `ldap`

  valid value:

  between 1 and 128 printable ASCII characters, excluding double quotes and backslashes

  ***

  Realm included in the `WWW-Authenticate` challenge returned with an authentication failure.
