elwig-backend: Add /auth endpoint

This commit is contained in:
2025-04-29 23:49:11 +02:00
parent bc17b842a4
commit 60be49d31d
2 changed files with 275 additions and 24 deletions
+59
View File
@@ -11,6 +11,65 @@ Authorization
-------------
All API endpoints are secured via an HTTP basic authentication.
Additionally, the `/auth` endpoint may be used to obtain a Bearer/JWT token.
### `GET /auth`
#### Example
```http
GET /auth HTTP/1.1
Host: example.com
Accept: application/json
Authorization: Basic dGVzdDp0ZXN0
```
```http
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 185
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Authorization
Access-Control-Allow-Methods: HEAD, GET, POST, OPTIONS
{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJleGFtcGxlLmNvbSIsInN1YiI6InRlc3QiLCJyb2wiOiJleHRlcm5hbCIsImlhdCI6MTc0NTgzMTQzN30.VMLz20aWI8nSd7ocT2W750Cy80OJs8OMiQCtq5Df0rE"}
```
### `POST /auth`
#### Example
```http
POST /auth HTTP/1.1
Host: example.com
Accept: application/json
Content-Type: application/json
Content-Length: 44
{"username": "test", "password": "password"}
```
```http
POST /auth HTTP/1.1
Host: example.com
Accept: application/json
Content-Type: application/x-www-form-urlencoded
Content-Length: 31
username=test&password=password
```
```http
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 185
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Authorization
Access-Control-Allow-Methods: HEAD, GET, POST, OPTIONS
{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJleGFtcGxlLmNvbSIsInN1YiI6InRlc3QiLCJyb2wiOiJleHRlcm5hbCIsImlhdCI6MTc0NTgzMTQzN30.VMLz20aWI8nSd7ocT2W750Cy80OJs8OMiQCtq5Df0rE"}
```
Base Data