Skip to content

Commit b59f28f

Browse files
committed
docs: add an example for a simple callable based custom auth
1 parent e70d0b0 commit b59f28f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

docs/advanced/authentication.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,16 @@ When issuing requests or instantiating a client, the `auth` argument can be used
9393
* A callable, accepting a request and returning an authenticated request instance.
9494
* An instance of subclasses of `httpx.Auth`.
9595

96-
The most involved of these is the last, which allows you to create authentication flows involving one or more requests. A subclass of `httpx.Auth` should implement `def auth_flow(request)`, and yield any requests that need to be made...
96+
The simplest way to implement a custom authentication scheme is to use a callable that accepts a single request and modifies it in place:
97+
98+
```python
99+
def custom_auth(request):
100+
request.headers["X-Auth-Token"] = "1234"
101+
102+
httpx.get("https://www.example.com", auth=custom_auth)
103+
```
104+
105+
The most involved is the last, which allows you to create authentication flows involving one or more requests. A subclass of `httpx.Auth` should implement `def auth_flow(request)`, and yield any requests that need to be made...
97106

98107
```python
99108
class MyCustomAuth(httpx.Auth):

0 commit comments

Comments
 (0)