Skip to content

Commit 533f231

Browse files
authored
AppAPI 2.0 (#212)
See: nextcloud/app_api#213 1. _All Talk Bots should be updated to use AppAPI auth for input endpoints._ 2. Updated Documentation reflecting last changes. 3. CI will fail, until merge in AppAPI will finished. --------- Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
1 parent a4f31b6 commit 533f231

File tree

26 files changed

+100
-126
lines changed

26 files changed

+100
-126
lines changed

.run/Skeleton (27).run.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Skeleton (27)" type="PythonConfigurationType" factoryName="Python">
33
<module name="nc_py_api" />
4+
<option name="ENV_FILES" value="" />
45
<option name="INTERPRETER_OPTIONS" value="" />
56
<option name="PARENT_ENVS" value="true" />
67
<envs>
8+
<env name="APP_HOST" value="0.0.0.0" />
79
<env name="APP_ID" value="skeleton" />
810
<env name="APP_PORT" value="9030" />
911
<env name="APP_SECRET" value="12345" />
1012
<env name="APP_VERSION" value="1.0.0" />
1113
<env name="NEXTCLOUD_URL" value="http://stable27.local/index.php" />
1214
<env name="PYTHONUNBUFFERED" value="1" />
13-
<env name="APP_HOST" value="0.0.0.0" />
1415
</envs>
1516
<option name="SDK_HOME" value="" />
1617
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/examples/as_app/skeleton/lib" />

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## [0.8.1 - 2024-01-xx]
5+
## [0.9.0 - 2024-01-25]
66

77
### Added
88

@@ -12,7 +12,9 @@ All notable changes to this project will be documented in this file.
1212

1313
### Changed
1414

15+
- **large amount of incompatible changes** for `AppAPI 2.0`, see PR for description. #212
1516
- class `Share`.raw_data marked as deprecated and changed to `_raw_data`. #206
17+
- `ex_app.talk_bot_app`/`ex_app.atalk_bot_app` renamed to `ex_app.talk_bot_msg`/`ex_app.atalk_bot_msg`.
1618

1719
## [0.8.0 - 2024-01-12]
1820

docs/NextcloudApp.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ First register ``manual_install`` daemon:
6666

6767
.. code-block:: shell
6868
69-
php occ app_api:daemon:register manual_install "Manual Install" manual-install 0 0 0
69+
php occ app_api:daemon:register manual_install "Manual Install" manual-install http host.docker.internal 0
7070
7171
Then, launch your application. Since this is a manual deployment, it's your responsibility to set minimum of the environment variables.
7272
Here they are:
@@ -86,7 +86,7 @@ After launching your application, execute the following command in the Nextcloud
8686
.. code-block:: shell
8787
8888
php occ app_api:app:register YOUR_APP_ID manual_install --json-info \
89-
"{\"appid\":\"YOUR_APP_ID\",\"name\":\"YOUR_APP_DISPLAY_NAME\",\"daemon_config_name\":\"manual_install\",\"version\":\"YOU_APP_VERSION\",\"secret\":\"YOUR_APP_SECRET\",\"host\":\"host.docker.internal\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"port\":SELECTED_PORT,\"protocol\":\"http\",\"system_app\":0}" \
89+
"{\"appid\":\"YOUR_APP_ID\",\"name\":\"YOUR_APP_DISPLAY_NAME\",\"daemon_config_name\":\"manual_install\",\"version\":\"YOU_APP_VERSION\",\"secret\":\"YOUR_APP_SECRET\",\"scopes\":{\"required\":[\"ALL\"],\"optional\":[]},\"port\":SELECTED_PORT,\"system_app\":0}" \
9090
--force-scopes --wait-finish
9191
9292
You can see how **nc_py_api** registers in ``scripts/dev_register.sh``.
@@ -226,8 +226,7 @@ and since this is not directly related to working with NextCloud, we will skip t
226226
Using AppAPIAuthMiddleware
227227
--------------------------
228228

229-
If your application does not implement `Talk Bot` functionality and you most often do not need
230-
the ``NextcloudApp`` class returned after standard authentication with `Depends`:
229+
If in your application in most cases you don't really need the ``NextcloudApp`` class returned after standard authentication using `Depends`:
231230

232231
.. code-block:: python
233232

docs/NextcloudTalkBot.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,18 @@ Afterward, using FastAPI, you can define endpoints that will be invoked by Talk:
4040
4141
@APP.post("/currency_talk_bot")
4242
async def currency_talk_bot(
43-
message: Annotated[talk_bot.TalkBotMessage, Depends(talk_bot_app)],
43+
_nc: Annotated[NextcloudApp, Depends(nc_app)],
44+
message: Annotated[talk_bot.TalkBotMessage, Depends(atalk_bot_msg)],
4445
background_tasks: BackgroundTasks,
4546
):
4647
return Response()
4748
4849
.. note::
49-
You must include to each endpoint your bot provides the **Depends(talk_bot_app)**.
50-
**message: Annotated[talk_bot.TalkBotMessage, Depends(talk_bot_app)]**
50+
You must include to each endpoint your bot provides the **Depends(nc_app)**.
5151

52-
Depending on **talk_bot_app** serves as an automatic authentication handler for messages from the cloud, which returns the received message from Nextcloud upon successful authentication.
52+
Depending on **nc_app** serves as an automatic authentication handler for messages from the cloud.
53+
54+
**message: Annotated[talk_bot.TalkBotMessage, Depends(talk_bot_app)]** - returns the received message from Nextcloud upon successful authentication.
5355

5456
Additionally, if your bot can provide quick and fixed execution times, you may not need to create background tasks.
5557
However, in most cases, it's recommended to segregate functionality and perform operations in the background, while promptly returning an empty response to Nextcloud.

examples/as_app/skeleton/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ run:
6969
register27:
7070
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister skeleton --silent --force || true
7171
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:register skeleton manual_install --json-info \
72-
"{\"appid\":\"skeleton\",\"name\":\"App Skeleton\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9030,\"scopes\":{\"required\":[],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
72+
"{\"appid\":\"skeleton\",\"name\":\"App Skeleton\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9030,\"scopes\":{\"required\":[],\"optional\":[]},\"system_app\":0}" \
7373
--force-scopes --wait-finish
7474

7575
.PHONY: register28
7676
register28:
7777
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:unregister skeleton --silent --force || true
7878
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:register skeleton manual_install --json-info \
79-
"{\"appid\":\"skeleton\",\"name\":\"App Skeleton\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9030,\"scopes\":{\"required\":[],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
79+
"{\"appid\":\"skeleton\",\"name\":\"App Skeleton\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9030,\"scopes\":{\"required\":[],\"optional\":[]},\"system_app\":0}" \
8080
--force-scopes --wait-finish
8181

8282
.PHONY: register
8383
register:
8484
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:unregister skeleton --silent --force || true
8585
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register skeleton manual_install --json-info \
86-
"{\"appid\":\"skeleton\",\"name\":\"App Skeleton\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9030,\"scopes\":{\"required\":[],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
86+
"{\"appid\":\"skeleton\",\"name\":\"App Skeleton\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9030,\"scopes\":{\"required\":[],\"optional\":[]},\"system_app\":0}" \
8787
--force-scopes --wait-finish

examples/as_app/skeleton/appinfo/info.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
<optional>
3131
</optional>
3232
</scopes>
33-
<protocol>http</protocol>
3433
<system>false</system>
3534
</external-app>
3635
</info>

examples/as_app/talk_bot/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ run27:
5454
register:
5555
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:unregister talk_bot --silent --force || true
5656
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register talk_bot manual_install --json-info \
57-
"{\"appid\":\"talk_bot\",\"name\":\"TalkBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9032,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
57+
"{\"appid\":\"talk_bot\",\"name\":\"TalkBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9032,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"system_app\":0}" \
5858
--force-scopes --wait-finish
5959

6060
.PHONY: register27
6161
register27:
62-
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister talk_bot --silent --force || true
62+
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister talk_bot --force || true
6363
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:register talk_bot manual_install --json-info \
64-
"{\"appid\":\"talk_bot\",\"name\":\"TalkBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9032,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
64+
"{\"appid\":\"talk_bot\",\"name\":\"TalkBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9032,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"system_app\":0}" \
6565
--force-scopes --wait-finish

examples/as_app/talk_bot/appinfo/info.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<optional>
3333
</optional>
3434
</scopes>
35-
<protocol>http</protocol>
3635
<system>false</system>
3736
</external-app>
3837
</info>

examples/as_app/talk_bot/lib/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from fastapi import BackgroundTasks, Depends, FastAPI, Response
99

1010
from nc_py_api import NextcloudApp, talk_bot
11-
from nc_py_api.ex_app import run_app, set_handlers, talk_bot_app
11+
from nc_py_api.ex_app import atalk_bot_msg, nc_app, run_app, set_handlers
1212

1313

1414
# The same stuff as for usual External Applications
@@ -66,7 +66,8 @@ def currency_talk_bot_process_request(message: talk_bot.TalkBotMessage):
6666

6767
@APP.post("/currency_talk_bot")
6868
async def currency_talk_bot(
69-
message: Annotated[talk_bot.TalkBotMessage, Depends(talk_bot_app)],
69+
_nc: Annotated[NextcloudApp, Depends(nc_app)],
70+
message: Annotated[talk_bot.TalkBotMessage, Depends(atalk_bot_msg)],
7071
background_tasks: BackgroundTasks,
7172
):
7273
# As during converting, we do not process converting locally, we perform this in background, in the background task.

examples/as_app/talk_bot_ai/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ run27:
5454
register:
5555
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:unregister talk_bot_ai --silent --force || true
5656
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register talk_bot_ai manual_install --json-info \
57-
"{\"appid\":\"talk_bot_ai\",\"name\":\"TalkBotAI\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9034,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
57+
"{\"appid\":\"talk_bot_ai\",\"name\":\"TalkBotAI\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9034,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"system_app\":0}" \
5858
--force-scopes --wait-finish
5959

6060
.PHONY: register27
6161
register27:
6262
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister talk_bot_ai --silent --force || true
6363
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:register talk_bot_ai manual_install --json-info \
64-
"{\"appid\":\"talk_bot_ai\",\"name\":\"TalkBotAI\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9034,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
64+
"{\"appid\":\"talk_bot_ai\",\"name\":\"TalkBotAI\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9034,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"system_app\":0}" \
6565
--force-scopes --wait-finish

examples/as_app/talk_bot_ai/appinfo/info.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<optional>
3333
</optional>
3434
</scopes>
35-
<protocol>http</protocol>
3635
<system>false</system>
3736
</external-app>
3837
</info>

examples/as_app/talk_bot_ai/lib/main.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
from transformers import pipeline
1010

1111
from nc_py_api import NextcloudApp, talk_bot
12-
from nc_py_api.ex_app import get_model_path, run_app, set_handlers, talk_bot_app
12+
from nc_py_api.ex_app import (
13+
atalk_bot_msg,
14+
get_model_path,
15+
nc_app,
16+
run_app,
17+
set_handlers,
18+
)
1319

1420

1521
@asynccontextmanager
@@ -34,7 +40,8 @@ def ai_talk_bot_process_request(message: talk_bot.TalkBotMessage):
3440

3541
@APP.post("/ai_talk_bot")
3642
async def ai_talk_bot(
37-
message: Annotated[talk_bot.TalkBotMessage, Depends(talk_bot_app)],
43+
_nc: Annotated[NextcloudApp, Depends(nc_app)],
44+
message: Annotated[talk_bot.TalkBotMessage, Depends(atalk_bot_msg)],
3845
background_tasks: BackgroundTasks,
3946
):
4047
if message.object_name == "message":

examples/as_app/to_gif/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ run:
6969
register27:
7070
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister to_gif --silent --force || true
7171
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:register to_gif manual_install --json-info \
72-
"{\"appid\":\"to_gif\",\"name\":\"to_gif\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9031,\"scopes\":{\"required\":[\"FILES\", \"NOTIFICATIONS\"],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
72+
"{\"appid\":\"to_gif\",\"name\":\"to_gif\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9031,\"scopes\":{\"required\":[\"FILES\", \"NOTIFICATIONS\"],\"optional\":[]},\"system_app\":0}" \
7373
--force-scopes --wait-finish
7474

7575
.PHONY: register28
7676
register28:
7777
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:unregister to_gif --silent --force || true
7878
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:register to_gif manual_install --json-info \
79-
"{\"appid\":\"to_gif\",\"name\":\"to_gif\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9031,\"scopes\":{\"required\":[\"FILES\", \"NOTIFICATIONS\"],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
79+
"{\"appid\":\"to_gif\",\"name\":\"to_gif\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9031,\"scopes\":{\"required\":[\"FILES\", \"NOTIFICATIONS\"],\"optional\":[]},\"system_app\":0}" \
8080
--force-scopes --wait-finish
8181

8282
.PHONY: register
8383
register:
8484
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:unregister to_gif --silent --force || true
8585
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register to_gif manual_install --json-info \
86-
"{\"appid\":\"to_gif\",\"name\":\"to_gif\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9031,\"scopes\":{\"required\":[\"FILES\", \"NOTIFICATIONS\"],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
86+
"{\"appid\":\"to_gif\",\"name\":\"to_gif\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9031,\"scopes\":{\"required\":[\"FILES\", \"NOTIFICATIONS\"],\"optional\":[]},\"system_app\":0}" \
8787
--force-scopes --wait-finish

examples/as_app/to_gif/appinfo/info.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<optional>
3333
</optional>
3434
</scopes>
35-
<protocol>http</protocol>
3635
<system>false</system>
3736
</external-app>
3837
</info>

examples/as_app/ui_example/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ run:
6969
register27:
7070
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister ui_example --silent --force || true
7171
docker exec master-stable27-1 sudo -u www-data php occ app_api:app:register ui_example manual_install --json-info \
72-
"{\"appid\":\"ui_example\",\"name\":\"UI Example\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9035,\"scopes\":{\"required\":[],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
72+
"{\"appid\":\"ui_example\",\"name\":\"UI Example\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9035,\"scopes\":{\"required\":[],\"optional\":[]},\"system_app\":0}" \
7373
--force-scopes --wait-finish
7474

7575
.PHONY: register28
7676
register28:
7777
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:unregister ui_example --silent --force || true
7878
docker exec master-stable28-1 sudo -u www-data php occ app_api:app:register ui_example manual_install --json-info \
79-
"{\"appid\":\"ui_example\",\"name\":\"UI Example\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9035,\"scopes\":{\"required\":[],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
79+
"{\"appid\":\"ui_example\",\"name\":\"UI Example\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9035,\"scopes\":{\"required\":[],\"optional\":[]},\"system_app\":0}" \
8080
--force-scopes --wait-finish
8181

8282
.PHONY: register
8383
register:
8484
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:unregister ui_example --silent --force || true
8585
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register ui_example manual_install --json-info \
86-
"{\"appid\":\"ui_example\",\"name\":\"UI Example\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9035,\"scopes\":{\"required\":[],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
86+
"{\"appid\":\"ui_example\",\"name\":\"UI Example\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9035,\"scopes\":{\"required\":[],\"optional\":[]},\"system_app\":0}" \
8787
--force-scopes --wait-finish

examples/as_app/ui_example/appinfo/info.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
<optional>
3131
</optional>
3232
</scopes>
33-
<protocol>http</protocol>
3433
<system>false</system>
3534
</external-app>
3635
</info>

nc_py_api/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Version of nc_py_api."""
22

3-
__version__ = "0.8.1.dev0"
3+
__version__ = "0.9.0.dev0"

nc_py_api/ex_app/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from .integration_fastapi import (
55
AppAPIAuthMiddleware,
66
anc_app,
7-
atalk_bot_app,
7+
atalk_bot_msg,
88
nc_app,
99
set_handlers,
10-
talk_bot_app,
10+
talk_bot_msg,
1111
)
1212
from .misc import get_model_path, persistent_storage, verify_version
1313
from .ui.files_actions import UiActionFileInfo

nc_py_api/ex_app/integration_fastapi.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""FastAPI directly related stuff."""
22

33
import asyncio
4-
import hashlib
5-
import hmac
64
import json
75
import os
86
import typing
@@ -21,7 +19,7 @@
2119

2220
from .._misc import get_username_secret_from_headers
2321
from ..nextcloud import AsyncNextcloudApp, NextcloudApp
24-
from ..talk_bot import TalkBotMessage, aget_bot_secret, get_bot_secret
22+
from ..talk_bot import TalkBotMessage
2523
from .misc import persistent_storage
2624

2725

@@ -49,26 +47,14 @@ def anc_app(request: HTTPConnection) -> AsyncNextcloudApp:
4947
return nextcloud_app
5048

5149

52-
def __talk_bot_app(secret: bytes | None, request: Request, body: bytes) -> TalkBotMessage:
53-
if not secret:
54-
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
55-
hmac_sign = hmac.new(
56-
secret, request.headers.get("X-NEXTCLOUD-TALK-RANDOM", "").encode("UTF-8"), digestmod=hashlib.sha256
57-
)
58-
hmac_sign.update(body)
59-
if request.headers["X-NEXTCLOUD-TALK-SIGNATURE"] != hmac_sign.hexdigest():
60-
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
61-
return TalkBotMessage(json.loads(body))
62-
63-
64-
def talk_bot_app(request: Request) -> TalkBotMessage:
50+
def talk_bot_msg(request: Request) -> TalkBotMessage:
6551
"""Authentication handler for bot requests from Nextcloud Talk to the application."""
66-
return __talk_bot_app(get_bot_secret(request.url.components.path), request, asyncio.run(request.body()))
52+
return TalkBotMessage(json.loads(asyncio.run(request.body())))
6753

6854

69-
async def atalk_bot_app(request: Request) -> TalkBotMessage:
55+
async def atalk_bot_msg(request: Request) -> TalkBotMessage:
7056
"""Async Authentication handler for bot requests from Nextcloud Talk to the application."""
71-
return __talk_bot_app(await aget_bot_secret(request.url.components.path), request, await request.body())
57+
return TalkBotMessage(json.loads(await request.body()))
7258

7359

7460
def set_handlers(

0 commit comments

Comments
 (0)