Skip to main content

Authorization

Authorization of the API is implemented with JWT (Jason Web Tokens). To request a token you can use the Swagger API documentation. Click on the login section and select Try out. In the request body enter the credentials. Make sure you quote the keys and the values.

Click on Execute and go to the response body section. Copy the token.

{
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoib...."
}

In the Swagger API click on Authorize and paste the token. You can now use the other API functions without having to enter authorization information.

Curl

Alternatively you can use curl to request an JWT access token.

curl -X 'POST' \
'https://server.localhost/login' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"userName": "me",
"password": "secret"
}'

To test the token you can request all data with topic weather:

curl -X 'GET' \
'https://server.3d-t.it/states?topic=weather&value=fog' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoib...'

The result is a JSON array with all state objects:

[
{
"spacetime": [
51.41191,
5.44969,
0,
"2021-11-03T14:45:04.539Z"
],
"topic": "weather.eersel.temperature",
"updated": "2021-04-06T11:00:01.730Z",
"value": 9,
},
...