Code Monkey home page Code Monkey logo

fastapi_users_docker's Introduction

User authentication using FastAPI (a python frameworks), MongoDB (for database), Docker Compose (for deployment)

How to start the application

Watch the video: (below the video are the commands on how to start the application)

The commands:

First you have to git clone the files by entering in your terminal:

$ git clone https://github.com/AtamanKit/fastapi_users_docker.git

Then start the application:

$ docker-compose up -d

The above command will both create the images and start the containers (2 images and 2 containers - one for the FastAPI application and one for the MongoDB database).

For visualizing the application, open up your browser and enter:

In the application we have seven sections:

  • For authentication (the right green "Authorize" button from the above);
  • For creating users (3 roles are acceptable only: "admin", "dev", "simple mortal", you'll see an error if not respecting the rule);
  • For creating tokens by entering user's credentials;
  • For listing the users;
  • For watching the current user (only if authenticated);
  • For modifying user properties (only if authenticated with admin role);
  • For deleting the user.

To see the runing containers in docker, enter in the terminal:

$ docker ps

To see the database and collection created (database name is: myTestDB, collection: users) enter in your terminal:

$ docker exec -it <container-id> bash

Configuration and file structure

Our file structure is:

.
├── app
│   ├── Dockerfile
│   ├── __init__.py
│   ├── main.py
│   ├── requirements.txt
│   └── src
│       ├── __init__.py
│       ├── dependecies.py
│       ├── models.py
│       ├── routers.py
│       └── settings.py
└── docker-compose.yml

In the app directory in main.py file we make all the dependencies and routers importing from the same name files located in src directory.

src directory is the one that containes all the needed pydantic models (models.py), database and authentication variables (settings.py).

Authentication is made by using bearer scheme with token creation and usage.

dependecies.py is the file containing authentication fucntions (I also made an authentication middleware located in main.py file in the root directory using basic scheme, this function serves as an example purpose only).

fastapi_users_docker's People

Contributors

atamankit 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.