Coder Social home page Coder Social logo

narcisolobo / auth Goto Github PK

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

This app was created to learn how to implement authorization and authentication in Flask.

Python 51.94% HTML 44.79% Mako 1.67% Shell 0.10% CSS 1.50%
bootstrap bootstrap5 flask flask-bcrypt flask-login flask-sqlalchemy flask-wtforms jinja2 flask-migrate auth

auth's Introduction

Flask Auth

License GitHub Stars GitHub Issues GitHub Forks

I made this project to learn how to implement a few auth-related Flask plugins. This app uses the app factory pattern with blueprints and the following plugins: Flask-Bcrypt, Flask-Login, Flask-Migrate, Flask-SQLAlchemy, and Flask-WTForms.

Table of Contents

Introduction

Flask was the first web framework that I learned back in 2018. I did not attempt to implement any popular Flask plugins at the time, mostly because I didn't know they existed. After learning basic Flask concepts, I quickly moved to Django.

Django is amazing, but it does a lot of things for you. In order to gain a better understanding of auth flow, I decided to go back to Flask and implement a DIY auth flow using only Flask, raw SQL, and Flask-Bcrypt. After getting a good handle on all of that, I wanted an ORM, an easier way to track user authentication, and hassle-free form validation.

That brings me to Flask Auth. With this project, I have hit all the goals I set out before me. I'm confident in what I have implemented, and I'm glad to have learned how to crawl before running.

Moving forward, I'll add another model to learn how to implement a one-to-many relationship with Flask-SQLAlchemy.

Features

List the key features of your project. For example:

  • User Registration: Users can fill out a WTForm to register. If the form is valid, their raw password is hashed using Flask-Bcrypt, and a new user is created and saved to the database.
  • User Login: Users can fill out a form to log into the site. If the form is valid, the app searches for the user via their email address. If the user is found, the app then checks their password against the hashed password in the database. If all is well, a session is created and the user is added to it. Finally, the user is redirected to the dashboard.
  • Protected Routes: A user must be authenticated to access the dashboard.
  • Form Validation: All form validations are handled with the Flask-WTForms plugin.
  • Bootstrap 5.3.1: At the time of first commit, the most recent version of Bootstrap is used for styling. Dark mode is enabled by default.

Installation

git clone https://github.com/narcisolobo/auth.git
cd auth
pipenv install

Usage

To run this app, please rename .env.example to .env and replace the SECRET_KEY value with one of your own. Per the Flask documentation:

A secret key that will be used for securely signing the session cookie and can be used for any other security related needs by extensions or your application. It should be a long random bytes or str.

I usually generate my secret keys in the Python shell using the token_hex method found in the secrets module.

# python shell
>>> from secrets import token_hex
>>> print(token_hex())

Exit the shell and run the app by executing the server.py file.

# Mac
python3 server.py

# Windows
python server.py

Contributing

I wholeheartedly welcome contributions to my project, whether through bug reports, feature requests, or pull requests.

## How to Contribute

1. Fork the repository.
2. Create a new branch.
3. Make your changes and commit them.
4. Push your changes to your fork.
5. Submit a pull request.

License

This project is licensed under the MIT License.

Acknowledgments

While I did not follow it to a T, I consulted the below article from Digital Ocean while creating this app.
How To Add Authentication to Your App with Flask-Login


auth's People

Contributors

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