Skip to content

Commit 00bf9ab

Browse files
committed
GH-42: Update documentation according to the changes
1 parent fea2234 commit 00bf9ab

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

docs/integration/integration.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,24 @@ section covers its integration into a FastAPI app.
1111

1212
The `OAuth2Middleware` is an authentication middleware which means that its usage makes the `user` and `auth` attributes
1313
available in the [request](https://www.starlette.io/requests/) context. It has a mandatory argument `config` of
14-
[`OAuth2Config`](/integration/configuration#oauth2config) instance that has been discussed at the previous section and
15-
an optional argument `callback` which is a callable that is called when the authentication succeeds.
14+
[`OAuth2Config`](/integration/configuration#oauth2config) instance that has been discussed in the previous section and
15+
optional arguments `callback` and `on_error` that accept callables as values and are called when the authentication
16+
succeeds and fails correspondingly.
1617

1718
```python
1819
app: FastAPI
1920

2021
def on_auth_success(auth: Auth, user: User):
2122
"""This could be async function as well."""
2223

24+
def on_auth_error(conn: HTTPConnection, exc: Exception) -> Response:
25+
return JSONResponse({"detail": str(exc)}, status_code=400)
26+
2327
app.add_middleware(
2428
OAuth2Middleware,
2529
config=OAuth2Config(...),
2630
callback=on_auth_success,
31+
on_error=on_auth_error,
2732
)
2833
```
2934

docs/references/tutorials.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ async def error_handler(request: Request, exc: OAuth2AuthenticationError):
140140
return RedirectResponse(url="/login", status_code=303)
141141
```
142142

143-
The complete list of exceptions is the following.
143+
The complete list of exceptions raised by the middleware is the following.
144144

145145
- `OAuth2Error` - Base exception for all errors raised by the FastAPI OAuth2 library.
146146
- `OAuth2AuthenticationError` - An exception is raised when the authentication fails.

0 commit comments

Comments
 (0)