Skip to content

Commit a7893aa

Browse files
committed
chore: docs, fix type annotation
1 parent 7c172f9 commit a7893aa

4 files changed

Lines changed: 69 additions & 41 deletions

File tree

.markdownlint.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"MD013": false,
3+
"MD024": false
4+
}

asgi_webdav/auth.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ async def check_ldap_password_v1(
167167

168168
async def check_ldap_password_v2(
169169
self, username: str, password: str
170-
) -> (bool, str | None):
170+
) -> tuple[bool, str | None]:
171171
"""
172172
<ldap>#2#{ldap-uri}#{ldap-params}#{ldap-user}
173173
<ldap>#2#ldaps:/your.domain.com#cert_policy=try#uid={username},cn=users,cn=accounts,dc=domain,dc=tld
@@ -581,6 +581,8 @@ async def pick_out_user(self, request: DAVRequest) -> tuple[DAVUser | None, str]
581581
# The user does not exist in the data file, but may be in the LDAP fallback.
582582
# Copy the data to avoid overwriting the template for future sessions.
583583
fallback = self.user_mapping.get("*ldap")
584+
# All future third-party authentication backends will begin with "*"
585+
# - use "*ldap" for ldap.
584586
if fallback is None:
585587
# A fallback is not configured.
586588
return None, "no permission"

docs/changelog.en.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Changelog
22

3-
4-
## 1.4.2 - 20250424
3+
## x.y.z - ?
54

65
- Allow authenticating any user from LDAP server, thanks [PIC](https://www.pic.es)
76

docs/guide/protect-your-password-in-the-config.en.md

Lines changed: 61 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22

33
```json
44
{
5-
"account_mapping": [
6-
{"username": "user-raw", "password": "password", "permissions": ["+"]},
7-
{
8-
"username": "user-hashlib",
9-
"password": "<hashlib>:sha256:salt:291e247d155354e48fec2b579637782446821935fc96a5a08a0b7885179c408b",
10-
"permissions": ["+^/$"]
11-
},
12-
{
13-
"username": "user-digest",
14-
"password": "<digest>:ASGI-WebDAV:c1d34f1e0f457c4de05b7468d5165567",
15-
"permissions": ["+^/$"]
16-
},
17-
{
18-
"username": "user-ldap",
19-
"password": "<ldap>#1#ldaps://your.ldap.server.com#SIMPLE#uid=user-ldap,cn=users,dc=your.ldap.server.com",
20-
"permissions": ["+^/$"]
21-
},
22-
{
23-
"username": "*",
24-
"password": "<ldap>#2#ldaps://your.ldap.server.com#cert_policy=try#uid={username},cn=users,dc=your.ldap.server.com",
25-
"permissions": ["+^/$"]
26-
}
27-
]
5+
"account_mapping": [
6+
{ "username": "user-raw", "password": "password", "permissions": ["+"] },
7+
{
8+
"username": "user-hashlib",
9+
"password": "<hashlib>:sha256:salt:291e247d155354e48fec2b579637782446821935fc96a5a08a0b7885179c408b",
10+
"permissions": ["+^/$"]
11+
},
12+
{
13+
"username": "user-digest",
14+
"password": "<digest>:ASGI-WebDAV:c1d34f1e0f457c4de05b7468d5165567",
15+
"permissions": ["+^/$"]
16+
},
17+
{
18+
"username": "user-ldap",
19+
"password": "<ldap>#1#ldaps://your.ldap.server.com#SIMPLE#uid=user-ldap,cn=users,dc=your.ldap.server.com",
20+
"permissions": ["+^/$"]
21+
},
22+
{
23+
"username": "*ldap",
24+
"password": "<ldap>#2#ldaps://your.ldap.server.com#cert_policy=try#uid={username},cn=users,dc=your.ldap.server.com",
25+
"permissions": ["+^/$"]
26+
}
27+
]
2828
}
2929
```
3030

@@ -37,6 +37,7 @@ user `user-raw`'s password is real password
3737
`password`'s format is `"<hashlib>:{algorithm}:{salt}:{hashed-password}"`
3838

3939
### {algorithm}
40+
4041
A list of supported `{algorithms}` can be found at [Python's docs](https://docs.python.org/3.10/library/hashlib.html)
4142

4243
The commonly used algorithms:
@@ -48,9 +49,11 @@ The commonly used algorithms:
4849
- blake2s (optimized for 8- to 32-bit platforms)
4950

5051
### {salt}
52+
5153
`{salt}` can be any string
5254

5355
### {hashed-password}
56+
5457
`{hashed-password}`'s format is `ALGORITHM(bytes("{salt}:{password}")).hexdigest()`
5558

5659
example:
@@ -59,23 +62,26 @@ example:
5962
- {salt}: `salt`
6063
- {password}: `password`
6164

62-
```
65+
```text
6366
>>> import hashlib
6467
>>> hashlib.new("sha256", "{}:{}".format("salt", "password").encode("utf-8")).hexdigest()
6568
'291e247d155354e48fec2b579637782446821935fc96a5a08a0b7885179c408b'
6669
```
6770

6871
### Ref
6972

70-
- https://en.wikipedia.org/wiki/Comparison_of_cryptographic_hash_functions
73+
- <https://en.wikipedia.org/wiki/Comparison_of_cryptographic_hash_functions>
7174

7275
## HTTP Digest Mode
76+
7377
`password`'s format is `<digest>:{realm}:{HA1}`
7478

7579
### {realm}
80+
7681
`ASGI-WebDAV`
7782

7883
### {HA1}
84+
7985
`{HA1}`'s format is `md5(bytes("{username}:{realm}:{password}")).hexdigest()`
8086

8187
example:
@@ -84,26 +90,30 @@ example:
8490
- {realm}: `ASGI-WebDAV`
8591
- {password}: `password`
8692

87-
```
93+
```text
8894
>>> import hashlib
8995
>>> hashlib.new("md5", "{}:{}:{}".format("user-digest", "ASGI-WebDAV", "password").encode("utf-8")).hexdigest()
9096
'c1d34f1e0f457c4de05b7468d5165567'
9197
```
9298

9399
### Ref
100+
94101
- [RFC2617](https://datatracker.ietf.org/doc/html/rfc2617)
95102

96-
## LDAP Mode (experimental)
97-
`password`'s format is `"<ldap>#1#{ldap-uri}#{mechanism}#{ldap-user}"`
103+
## LDAP(v1) (experimental)
104+
105+
### password format
106+
107+
```text
108+
"<ldap>#1#{ldap-uri}#{mechanism}#{ldap-user}"
109+
```
98110

99111
### {ldap-uri}
100112

101113
Example:
102114

103115
`ldap://your.ldap.server.com` `ldaps://your.tls.ldap.server.com`
104116

105-
#### Ref
106-
107117
- [Official Website](https://ldap.com/ldap-urls/)
108118
- [RFC4516](https://docs.ldap.com/specs/rfc4516.txt)
109119

@@ -119,9 +129,22 @@ Example:
119129

120130
`uid=you-name,cn=users,dc=ldap,dc=server,dc=com`
121131

122-
## LDAP fallback
123-
Use `"*"` as `username` to use it as fallback for any user not explicitly set in the configuration file.
124-
`password`'s format is `"<ldap_users>#ldaps://{ldap-uri}#{params}#{user-dn-pattern}"`.
132+
## LDAP(v2)
133+
134+
### username
135+
136+
Use `"*"` as `username`
137+
138+
### password format
139+
140+
```text
141+
"<ldap_users>#ldaps://{ldap-uri}#{params}#{user-dn-pattern}"
142+
```
143+
144+
### permissions
145+
146+
WARNING:
147+
`permissions` will be automatically applied to all ldap accounts.
125148

126149
### {ldap-uri}
127150

@@ -140,8 +163,8 @@ This is a query string specifying additional optional settings. Only one is supp
140163

141164
`cert_policy` indicates the policy about server verification. The allowed values are:
142165

143-
* `try` or `demand`: The server cert will be verified, and if it fais, an error will be raised. This is the default.
144-
* `never` or `allow`: The server cert will be used without any verification.
166+
- `try` or `demand`: The server cert will be verified, and if it fais, an error will be raised. This is the default.
167+
- `never` or `allow`: The server cert will be used without any verification.
145168

146169
Example:
147170

@@ -151,7 +174,6 @@ Example:
151174

152175
- [RFC1866](https://datatracker.ietf.org/doc/html/rfc1866)
153176

154-
155177
### {user-dn-pattern}
156178

157179
Specify the user DN pattern, with a `username` substitution field. Example:
@@ -161,8 +183,9 @@ Specify the user DN pattern, with a `username` substitution field. Example:
161183
## Compatibility
162184

163185
| | HTTP Basic auth | HTTP Digest auth |
164-
|------------------|-----------------|------------------|
186+
| ---------------- | --------------- | ---------------- |
165187
| Raw Mode | Y | Y |
166188
| hashlib Mode | Y | N |
167189
| HTTP Digest Mode | Y | Y |
168-
| LDAP Mode | Y | N |
190+
| LDAP(v1) | Y | N |
191+
| LDAP(v2) | Y | N |

0 commit comments

Comments
 (0)