Skip to content

Commit 4e5adeb

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

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

docs/advanced/authentication.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,17 @@ 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+
return request
102+
103+
httpx.get("https://www.example.com", auth=custom_auth)
104+
```
105+
106+
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...
97107

98108
```python
99109
class MyCustomAuth(httpx.Auth):

0 commit comments

Comments
 (0)