Git Product home page Git Product logo

flask-oauth2-boilerplate's Introduction

Flask OAuth2 Boilerplate

Extensive Flask boilerplate using best practices with a focus on implementing an OAuth 2.0 client.

Features

  • OAuth 2.0 - Server-side authorization for Google, Facebook.
  • Flask-Login for local authorization, using Argon2 password hashing.
  • Flask app design using Blueprints and Application Factories.
  • Bootstrap 4 Beta as frontend.
  • SQLAlchemy ORM using relationships, constraints, joins, labels, ...
  • Loading data from JSON into database.
  • Flask-WTF forms with CSRF Protection, Jinja2 macros and dynamically generated QuerySelectField.
  • Using Flasks built-in integration of click CLI instead of Flask-Script.
  • REST API - JSON endpoints.
  • Extensive error handling, logging to console and log file.
  • Configuration from file.
  • Unit Tests with Coverage.
  • Pipenv as Python packaging tool.

OAuth 2.0 Client

There are many libraries available for OAuth 2.0 authorization. Google's oauth2client got recently deprecated and now they recommend google-auth with OAuthLib but their docs are not yet updated. Rauth is unmaintained. I decided to use Flask-OAuthlib, it uses Requests-OAuthlib which is a high-level client library built on OAuthLib & Requests. Please note that Google has also just released one-tap sign-up an auto sign-in on websites.
Currently supported providers: Google, Facebook.

Update @ 2018-01-08: apparently Flask-OAuthlib is now also deprecated and will be replaced by Authlib...

Flask Extensions

Keeping the extensions to a minimum, others can be easily integrated.

User Experience

Have a look in the Wiki to see how it looks.

Getting Started

Before you can integrate sign-in to your websites, set up your app at Google & Facebook.

Google

Create a Google API Console project and client ID.
Authorized JavaScript origins: http://localhost:5000
Authorized redirect URIs: http://localhost:5000/oauth2/sign-in/google/authorized
Add your client_id and client_secret in myapp/oauth2/google_client_secrets.json

Facebook

Create and retrieve a Facebook App ID on the App Dashboard.
Open Products > Facebook Login and enable Client OAuth Login and Web OAuth Login.
Valid OAuth redirect URIs: http://localhost:5000
Add your App ID and App Secret to myapp/oauth2/facebook_client_secrets.json

Set your Secret Keys

Generate your own secret keys and add them to files run_development.sh, run_testing.sh, run_testing_with_coverage.sh.

Run the Development Web Server

Create a virtual environment and start one of the shell scripts, this example uses Pipenv.

pip3 install --user pipenv
pipenv install #This installs everything from the pipfile.
./run_development.sh

What is next?

Adding multiple ways of sign in for websites, using provider APIs, JavaScript, ... I really hope that with your contributions, we can keep improving this template.

License

See the LICENSE file for license rights and limitations (MIT).

flask-oauth2-boilerplate's People

Contributors

berithpy avatar jsoetens avatar

Watchers

James Cloos 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.