Skip to content

Latest commit

 

History

History
113 lines (76 loc) · 3.86 KB

README.md

File metadata and controls

113 lines (76 loc) · 3.86 KB

Oauth2

PlayGround with JWTs used as OAuth 2.0 Bearer Tokens to encode all relevant parts of an access token into the access token itself instead of storing them in a database ⚙

Getting Started

Prerequisites

  • Python 3.6 or higher
  • FastAPI
  • Docker

Project setup

# clone the repo
$ git clone https://github.com/yezz123/Oauth2

# move to the project folder
$ cd Oauth2

Creating virtual environment

  • Install pipenv a global python project pip install pipenv
  • Create a virtual environment for this project
# creating pipenv environment for python 3
$ pipenv --three

# activating the pipenv environment
$ pipenv shell

# if you have multiple python 3 versions installed then
$ pipenv install -d --python 3.8

# install all dependencies (include -d for installing dev dependencies)
$ pipenv install -d

Environment Variables

  • SECRET_KEY: The secret key used to encode JWTs
  • ACCESS_TOKEN_EXPIRE_MINUTES: The number of minutes the access token is valid for
  • DATABASE_URL: The database url to connect to the database (SQLite)

Note: Don't forget to change the .env.sample file to .env and add your own values.

Running the Application

  • To run the Main we need to use uvicorn a lightning-fast ASGI server implementation, using uvloop and httptools.
# Run the app using uvicorn
$ uvicorn main:app --reload

Running the Docker Container

  • We have the Dockerfile created in above section. Now, we will use the Dockerfile to create the image of the FastAPI app and then start the FastAPI app container.
$ docker build
  • list all the docker images and you can also see the image oauth2:latest in the list.
$ docker images
  • run the application at port 5000. The various options used are:
  • -p: publish the container's port to the host port.
  • -d: run the container in the background.
  • -i: run the container in interactive mode.
  • -t: to allocate pseudo-TTY.
  • --name: name of the container
$ docker container run -p 5000:5000 -dit --name Oauth2 oauth2:latest
  • Check the status of the docker container
$ docker container ps

Preconfigured Packages

Includes preconfigured packages to kick start Oauth2 by just setting appropriate configuration.

Package Usage
uvicorn a lightning-fast ASGI server implementation, using uvloop and httptools.
Python-Jose a JavaScript Object Signing and Encryption implementation in Python.
SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL.
starlette a lightweight ASGI framework/toolkit, which is ideal for building high performance asyncio services.
passlib a password hashing library for Python 2 & 3, which provides cross-platform implementations of over 30 password hashing algorithms
bcrypt Good password hashing for your software and your servers.
python-multipart streaming multipart parser for Python.

yapf packages for linting and formatting

Contributing

  • Join the Oauth2 Creator and Contribute to the Project if you have any enhancement or add-ons to create a good and Secure Project, Help any User to Use it in a good and simple way.

License

This project is licensed under the terms of the MIT license.