diff --git a/royalnet/backpack/stars/api_token_create.py b/royalnet/backpack/stars/api_token_create.py index 831f3d7a..23a56f89 100644 --- a/royalnet/backpack/stars/api_token_create.py +++ b/royalnet/backpack/stars/api_token_create.py @@ -18,6 +18,8 @@ class ApiTokenCreateStar(ApiStar): tags = ["token"] + requires_auth = True + async def api(self, data: ApiData) -> ru.JSON: user = await data.user() try: diff --git a/royalnet/backpack/stars/api_token_info.py b/royalnet/backpack/stars/api_token_info.py index 3986e6dd..7626fc78 100644 --- a/royalnet/backpack/stars/api_token_info.py +++ b/royalnet/backpack/stars/api_token_info.py @@ -9,6 +9,8 @@ class ApiTokenInfoStar(ApiStar): tags = ["token"] + requires_auth = True + async def api(self, data: ApiData) -> ru.JSON: token = await data.token() return token.json() diff --git a/royalnet/backpack/stars/api_token_passwd.py b/royalnet/backpack/stars/api_token_passwd.py index 29a28d4b..6f04c496 100644 --- a/royalnet/backpack/stars/api_token_passwd.py +++ b/royalnet/backpack/stars/api_token_passwd.py @@ -9,15 +9,17 @@ from ..tables.tokens import Token class ApiTokenPasswdStar(ApiStar): path = "/api/token/passwd/v1" - methods = ["POST"] + methods = ["PUT"] summary = "Change Royalnet password for an user." + tags = ["token"] + parameters = { "new_password": "The password you want to set." } - tags = ["token"] + requires_auth = True async def api(self, data: ApiData) -> ru.JSON: TokenT = self.alchemy.get(Token) diff --git a/royalnet/backpack/stars/api_user_find.py b/royalnet/backpack/stars/api_user_find.py index c61b3fc3..009b8721 100644 --- a/royalnet/backpack/stars/api_user_find.py +++ b/royalnet/backpack/stars/api_user_find.py @@ -8,12 +8,12 @@ class ApiUserFindStar(ApiStar): summary = "Find a Royalnet user by one of their aliases." + tags = ["user"] + parameters = { "alias": "One of the aliases of the user to get." } - tags = ["user"] - async def api(self, data: ApiData) -> dict: user = await Alias.find_user(self.alchemy, data.session, data["alias"]) if user is None: diff --git a/royalnet/backpack/stars/docs.py b/royalnet/backpack/stars/docs.py index 4fb23645..fb395294 100644 --- a/royalnet/backpack/stars/docs.py +++ b/royalnet/backpack/stars/docs.py @@ -28,16 +28,13 @@ class DocsStar(PageStar): "paths": paths, "components": { "securitySchemes": { - "LoginTokenAuth": { + "RoyalnetLoginToken": { "type": "apiKey", "in": "query", "name": "token", } } - }, - "security": [ - {"LoginTokenAuth": []} - ] + } }) return HTMLResponse( diff --git a/royalnet/constellation/api/apistar.py b/royalnet/constellation/api/apistar.py index 62ccdd53..d7ba7549 100644 --- a/royalnet/constellation/api/apistar.py +++ b/royalnet/constellation/api/apistar.py @@ -19,6 +19,8 @@ class ApiStar(PageStar, ABC): tags: List[str] = [] + requires_auth: bool = False + async def page(self, request: Request) -> JSONResponse: if request.query_params: data = request.query_params @@ -74,4 +76,6 @@ class ApiStar(PageStar, ABC): "type": "string" } for parameter in cls.parameters] } + if cls.requires_auth: + result[method.lower()]["security"] = [{"RoyalnetLoginToken": ["logged_in"]}] return result diff --git a/royalnet/version.py b/royalnet/version.py index 214a6363..3e2df96c 100644 --- a/royalnet/version.py +++ b/royalnet/version.py @@ -1 +1 @@ -semantic = "5.6.1" +semantic = "5.6.2"