Default auth service based on FastApi framework
$ pip install fastapi-auth-user
or
for poetry:
$ poetry init
$ poetry add fastapi-auth-user- Create a file
main.pywith:
import uvicorn
from fastapi_auth_user import auth_app
if __name__ == "__main__":
uvicorn.run(auth_app, host="localhost", port=3000)Run the server with:
$ poetry run main.py or $ python3 main.py
INFO: Started server process [12484]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://localhost:3000 (Press CTRL+C to quit)Open your browser at http://localhost:3000/docs.
You already created an API that:
- All method CRUD for USER model`.
- All method CRUD for Role model`.
- Login user with oauth2
- Profile this user
DB_USER=<YOU USER NAME DB> #'postgres'
DB_PASSWORD=<YOU DATABASE PASSWORD> #'root'
DB_HOST=<YOU DATABASE HOST> #'localhost'
DB_NAME=<YOU DATABASE NAME> #'auth_db'
DATABASE_URL=<YOU DATABASE URL> #'postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}'
ACCESS_TOKEN_EXPIRE_MINUTES=<TIME FOR TOKEN> #30
SECRET_KEY=<SECRET KEY> #'secret_key'
ALGORITHM=<HASH ALGORITHM> #'HS256'
