Skip to content

Authentication#

Login#

POST /auth/login

Use the credentials created before in Quickstart to login.

Request#

1
2
3
4
5
POST /auth/login HTTP/1.1
Content-Type: application/json; charset=utf-8
Host: 0.0.0.0:8000

{"username":"user","password":"secret"}
1
2
3
4
5
6
curl -X "POST" "http://0.0.0.0:8000/auth/login" \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d '{
           "username": "user",
           "password": "secret"
         }'
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Install the Python Requests library:
# `pip install requests`

import requests

host = "http://0.0.0.0:8000"

user = {"username": "user", "password": "secret"}
response = requests.post(f"{host}/auth/login", user)

print(response.json())

Response#

1
{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."}
1
{"message": "Wrong credentials"}

Authorization header

Every new request you will made is necessary add this 'token' on authorization header.

Example#

1
2
GET /users/ HTTP/1.1
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
1
2
curl "http://0.0.0.0:8000/users/" \
     -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...'
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Install the Python Requests library:
# `pip install requests`

import requests

host  = "http://0.0.0.0:8000"
token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."

headers  = {"authorization": f"Bearer {token}"}
response = requests.get(f"{host}/users/", headers=headers)

print(response.json())

Login data#

Field Type Description
name string Username.
password string Password.