> For the complete documentation index, see [llms.txt](https://authing.gitbook.io/authing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://authing.gitbook.io/authing/authentication/ldap/ldap-idp.md).

# 使用 Authing 的 LDAP 用户目录

Authing 支持使用 LDAP 协议查看、修改、增加和删除用户信息。

Authing 支持使用 LDAP 协议查看、修改、增加和删除用户信息，本页面包含了一些基础信息和使用教程。

## 基本信息

| 信息 | 值 |
| -- | - |

| Hostname                | ldap\://ldap.authing.cn                                                    |
| ----------------------- | -------------------------------------------------------------------------- |
| Port                    | 1389                                                                       |
| LDAP Distinguished Name | cn=AUTHING\_USERNAME, ou=users, o=AUTHING\_USERPOOL\_ID, dc=authing, dc=cn |
| Base DN                 | ou=users, o=AUTHING\_USERPOOL\_ID, dc=authing, dc=cn                       |

## 认证方式

访问 Authing LDAP 服务器需要使用 Authing 的应用[密钥 (Secret)](/authing/others/faq.md#ru-he-huo-qu-client-id-he-client-secret)，认证命令如下所示：

```
$ ldapsearch -H ldap://ldap.authing.cn:1389 -x -D "ou=users,o=AUTHING_USERPOOL_ID,dc=authing,dc=cn" -w "AUTHING_USERPOOL_SECRET"  -LLL -b "ou=users,o=AUTHING_USERPOOL_ID,dc=authing,dc=cn"
```

若密钥 (Secret) 不正确会返回如下信息：

```
ldap_bind: Invalid credentials (49)
	matched DN: ou=users, o=AUTHING_USERPOOL_ID, dc=authing, dc=cn
	additional info: InvalidCredentialsError
```

## Search

```
$ ldapsearch -H ldap://ldap.authing.cn:1389 -x -D "ou=users,o=AUTHING_USERPOOL_ID,dc=authing,dc=cn" -w "AUTHING_USERPOOL_SECRET"  -LLL -b "ou=users,o=AUTHING_USERPOOL_ID,dc=authing,dc=cn"
```

## Add

创建一个名为 user.ldif 的文件然后复制以下内容进去：

```
dn: cn=authingUserName, ou=users, o=AUTHING_USERPOOL_ID, dc=authing, dc=cn
objectClass: users
cn: authingUserName
```

然后执行以下命令：

```
$ ldapadd -H ldap://ldap.authing.cn:1389 -x -D "ou=users,o=AUTHING_USERPOOL_ID,dc=authing,dc=cn" -w "AUTHING_USERPOOL_SECRET" -f ./user.ldif
```

## Modify

创建一个名为 modify.ldif 的文件然后复制以下内容进去：

```
dn: cn=secret, ou=users, o=AUTHING_USERPOOL_ID, dc=authing, dc=cn
changetype: modify
replace: mail
mail: test@authing.cn
```

然后执行以下命令：

```
$ ldapmodify -H ldap://ldap.authing.cn:1389 -x -D "ou=users,o=AUTHING_USERPOOL_ID,dc=authing,dc=cn" -w "AUTHING_USERPOOL_SECRET" -f ./modify.ldif
```

## Delete

```
$ ldapdelete -H ldap://ldap.authing.cn:1389 -x -D "ou=users,o=AUTHING_USERPOOL_ID,dc=authing,dc=cn" -w "AUTHING_USERPOOL_SECRET" "cn=authingUserName, ou=users, o=AUTHING_USERPOOL_ID, dc=authing,dc=cn"
```
