GithubHelp home page GithubHelp logo

matinone / fastapi_auth Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 128 KB

Complete user authentication using FastAPI.

License: MIT License

Python 96.95% Shell 0.51% Dockerfile 0.97% HTML 0.95% Mako 0.62%
api-rest fastapi factory-boy pytest sqlalchemy google-login oauth2 alembic python

fastapi_auth's Introduction

Testing

User Authentication with FastAPI

Complete user authentication support, with sample endpoints to handle users and create items in a per user ToDo list.

Features

  • User registration and login using username (email) and password (OAuth2) to create the user and generate access tokens.
  • User registration and login using Google credentials to create the user and generate access tokens.
  • Email account verification and password recovery.
  • Refresh tokens support.
  • Protected endpoints.
  • Interactive API documentation (provided by Swagger UI).
  • 100% test coverage (app/api/).
  • Python formatting and styling using black, isort and flake8.
  • Frontend using Vue available here.

Technologies / frameworks / tools

Running it locally

With or without Docker, the proper environment variables must be set before running the server. They can be externally set or a .env file can be used (see example.env for reference). All the env variables have reasonable default values.

The following commands must be run from the top level directory.

Without Docker

Locally, the environment variable ENVIRONMENT must be set to test, to use SQLite instead of PostgreSQL.

$ pip install -r requirements.txt
$ ENVIRONMENT=test uvicorn app.main:app

The server is now running at http://127.0.0.1:8000. The interactive API docs can be accessed from http://127.0.0.1:8000/docs.

With Docker

$ docker compose up -d

The server is now running at http://127.0.0.1:80. The interactive API docs can be accessed from http://127.0.0.1:80/docs. The pgAdmin platform can be accessed from http://127.0.0.1:5050, using email = [email protected] and password = admin to login (they are defined in the docker-compose.yml file).

With Kubernetes

To run the app in a single-node local Kubernetes cluster (using minikube), it is first required to update the existing YAML files in the /kubernetes directory:

  • Change the value of spec.template.spec.containers.image of the Deployment resource definition in fastapi_app.yaml, to use your own uploaded image in Docker Hub.
  • Set the path that will be used in the local machine to persist the database data, updating the value of spec.hostPath.path of the PersistentVolume resource definition in postgres_db.yaml.

Once the files have been updated, the following commands must be run to start the cluster and apply the desired configuration:

$ cd kubernetes
$ minikube start
$ kubectl apply -f=environment.yaml
$ kubectl apply -f=postgres_db.yaml
$ kubectl apply -f=fastapi_app.yaml

If all the resources are successfully created, then the command $ minikube service fastapi-service can be used to get the URL to access the app.

Finally, the command $ minikube delete --all can be used to delete the whole cluster.

Running tests

The following commands must be run from the top level directory.

$ pip install -r requirements.txt
$ pip install -r dev_requirements.txt
$ python -m pytest app/tests/ -v --cov=app/api

fastapi_auth's People

Contributors

matinone avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.