You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/NextcloudApp.rst
+39-36Lines changed: 39 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,24 +19,36 @@ Since this is a simple skeleton application, we only define the ``/enable`` endp
19
19
When the application receives a request at the endpoint ``/enable``,
20
20
it should register all its functionalities in the cloud and wait for requests from Nextcloud.
21
21
22
-
So, calling:
22
+
So, defining:
23
23
24
24
.. code-block:: python
25
25
26
-
set_handlers(APP, enabled_handler)
26
+
@asynccontextmanager
27
+
asyncdeflifespan(app: FastAPI):
28
+
set_handlers(app, enabled_handler)
29
+
yield
27
30
28
31
will register an **enabled_handler** that will be called **both when the application is enabled and disabled**.
29
32
30
33
During the enablement process, you should register all the functionalities that your application offers
31
34
in the **enabled_handler** and remove them during the disablement process.
32
35
33
-
The API is designed so that you don't have to check whether an endpoint is already registered
36
+
The AppAPI APIs is designed so that you don't have to check whether an endpoint is already registered
34
37
(e.g., in case of a malfunction or if the administrator manually altered something in the Nextcloud database).
35
-
The API will not fail, and in such cases, it will simply re-register without error.
38
+
The AppAPI APIs will not fail, and in such cases, it will simply re-register without error.
36
39
37
40
If any error prevents your application from functioning, you should provide a brief description in the return instead
38
41
of an empty string, and log comprehensive information that will assist the administrator in addressing the issue.
39
42
43
+
.. code-block:: python
44
+
45
+
APP= FastAPI(lifespan=lifespan)
46
+
APP.add_middleware(AppAPIAuthMiddleware)
47
+
48
+
With help of ``AppAPIAuthMiddleware`` you can add **global** AppAPI authentication for all future endpoints you will define.
49
+
50
+
.. note:: ``AppAPIAuthMiddleware`` supports **disable_for** optional argument, where you can list all routes for which authentication should be skipped.
51
+
40
52
Dockerfile
41
53
----------
42
54
@@ -86,7 +98,7 @@ After launching your application, execute the following command in the Nextcloud
Here we see: **nc: Annotated[NextcloudApp, Depends(nc_app)]**
236
237
237
-
APP= FastAPI(lifespan=lifespan)
238
-
APP.add_middleware(AppAPIAuthMiddleware)
238
+
For those who already know how FastAPI works, everything should be clear by now,
239
+
and for those who have not, it is very important to understand that:
239
240
240
-
and it will be called for all your endpoints and check the validity of the connection itself.
241
+
It is a declaration of FastAPI `dependency <https://fastapi.tiangolo.com/tutorial/dependencies/#dependencies>`_ to be executed
242
+
before the code of **video_to_gif** starts execution.
241
243
242
-
``AppAPIAuthMiddleware`` supports **disable_for** optional argument, where you can list all routes for which authentication should be skipped.
244
+
And this required dependency handles authentication and returns an instance of the :py:class:`~nc_py_api.nextcloud.NextcloudApp`
245
+
class that allows you to make requests to Nextcloud.
243
246
244
-
You can still use at the same time the *AppAPIAuthMiddleware* and *Depends(nc_app)*, it is clever enough and they won't interfere with each other.
247
+
.. note:: NcPyAPI is clever enough to detect whether global authentication handler is enabled, and not perform authentication twice for performance reasons.
245
248
246
249
This chapter ends here, but the next topics are even more intriguing.
0 commit comments