authorization: implement /access/info endpoint

Signed-off-by: Luca Schöneberg <luca-schoeneberg@outlook.com>
This commit is contained in:
Luca Schöneberg 2022-06-17 17:19:12 +02:00 committed by GitHub
parent a8b9fc0017
commit 58fa361c8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -2125,6 +2125,25 @@ to any API endpoint. The query string should be added in the form of:
?token={base32_random_token}
```
#### Retrieve information about authorization endpoints
HTTP Request:
```http
GET /access/info
```
JSON-RPC request: Not Available
Returns: An object containing information about authorization endpoints, such as
default_source and available_sources.
```json
{
"default_source": "moonraker",
"available_sources": [
"moonraker",
"ldap"
]
}
```
#### Get the Current API Key
HTTP request:
```http

View File

@ -220,6 +220,7 @@ class Authorization:
self.permitted_paths.add("/server/redirect")
self.permitted_paths.add("/access/login")
self.permitted_paths.add("/access/refresh_jwt")
self.permitted_paths.add("/access/info")
self.server.register_endpoint(
"/access/login", ['POST'], self._handle_login,
transports=['http'])
@ -244,6 +245,9 @@ class Authorization:
self.server.register_endpoint(
"/access/oneshot_token", ['GET'],
self._handle_oneshot_request, transports=['http'])
self.server.register_endpoint(
"/access/info", ['GET'],
self._handle_default_source_request, transports=['http'])
self.server.register_notification("authorization:user_created")
self.server.register_notification("authorization:user_deleted")
@ -287,6 +291,17 @@ class Authorization:
"action": "user_logged_out"
}
async def _handle_default_source_request(self,
web_request: WebRequest
) -> Dict[str, str | List[str]]:
sources = ["moonraker"]
if self.ldap is not None:
sources.append("ldap")
return {
"default_source": self.default_source,
"available_sources": sources
}
async def _handle_refresh_jwt(self,
web_request: WebRequest
) -> Dict[str, str]: