Flask OAuth, Dark-Mode, Docker - Free BS5 Starter
Tags: flask, opensource, dashboards
Published: 2022-09-16 16:06:29

---
title: Flask OAuth, Dark-Mode, Docker - Free BS5 Starter
published: true
description: Open-source seed project enhanced with OAuth for Github, Dark-Mode, DB tools (Flask-Migrate), and Docker Support - Soft Dashboard Design.
tags: flask, opensource, dashboards
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/al1khdg16m2vcnzhhhgx.jpg
canonical_url: https://blog.appseed.us/flask-soft-dashboard-oauth-docker-s72/
---
Hello Coders! 

This article presents the latest updates of [Soft UI Dashboard](https://appseed.us/product/soft-ui-dashboard/flask/), a popular open-source [Flask](https://appseed.us/admin-dashboards/flask/) starter recently updated to support *OAuth sign-in for Github, persistent dark mode, improved Docker scripts*, and other minor UI/UX improvements and fixes. The product, based on the permissive license, can be used in commercial projects or eLearning activities.  Thanks for reading!

- 👉 [Soft UI Dashboard Flask](https://appseed.us/product/soft-ui-dashboard/flask/) - Product page
- 👉 [Soft UI Dashboard Flask](https://flask-soft-ui-dashboard.appseed-srv1.com/) - LIVE Demo

---

## ✨Product Highlights

This simple starter provides a few basic features that might help designers and developers to start faster a new app powered by Flask.

- ✅ Up-to-date dependencies
- ✅ Database: MySql, SQLite
- ✅ Session-Based authentication
- ✅ Social Login (optional) for GitHub
- ✅ Docker Scripts
- ✅ BS5 design, Dark-Mode (persistent)

Probably the fastest way to start the project in a local environment is to execute the Docker setup, which is basically a single line typed in the terminal.

> 👉 **Step #1** - Clone/download source from Github

```bash
$ git clone https://github.com/app-generator/flask-soft-ui-dashboard.git
$ cd flask-soft-ui-dashboard
```

> 👉 **Step #2** - Start in Docker 

```bash
$ docker-compose up --build
```

Once the command finishes the execution, we should be able to visit the app in the browser.

![Soft Dashboard - Dark-Mode Sign In (Flask Starter).](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r8akx8dpjzx0qrsb149z.gif)

---

## ✨ OAuth Sign IN

The key feature of this release is the social authentication for GitHub implemented on top of the Flask-Dance library. The changes that activate this feature are highlighted below and also the link to the related commit is provided.

---

> 👉 `Flask OAuth` **Added modules** - [GH commit](https://github.com/app-generator/flask-soft-ui-dashboard/commit/5fde9779f803a991e11de99b9efa58767f7438e4)

```txt
Flask-Dance==5.1.0
blinker==1.4
```

Flask-Dance is the library that implements all the hard work like building the Github blueprint, processing the routing, and managing the authentication context for us.

---

> 👉 `Flask OAuth` **Update Configuration** - [GH commit](https://github.com/app-generator/flask-soft-ui-dashboard/commit/12930ffadff4099208299223365c4ad4aaa5a928)

```python
    SOCIAL_AUTH_GITHUB  = False

    GITHUB_ID      = os.getenv('GITHUB_ID')
    GITHUB_SECRET  = os.getenv('GITHUB_SECRET')

    # Enable/Disable Github Social Login    
    if GITHUB_ID and GITHUB_SECRET:
         SOCIAL_AUTH_GITHUB  = True
```

The feature becomes active if the app detects in `.env` file the secrets for Github. A valid `.env` file that enables the feature looks like this:

```env
# SOCIAL AUTH Github
GITHUB_ID=GITHUB_ID_value_here
GITHUB_SECRET=GITHUB_SECRET_value_here
```

---

> 👉 `Flask OAuth` **Github Blueprint** - [GH commit](https://github.com/app-generator/flask-soft-ui-dashboard/commit/5effd4659ecaa247f8ddf15f8027c9f57cffcfe9)

```python
# Truncated content

github_blueprint = make_github_blueprint(
    client_id=Config.GITHUB_ID,
    client_secret=Config.GITHUB_SECRET,
    scope = 'user',
    storage=SQLAlchemyStorage(
        OAuth,
        db.session,
        user=current_user,
        user_required=False,        
    ),   
)
```

---

> 👉 `Flask OAuth` **Users Model Update** - [GH commit](https://github.com/app-generator/flask-soft-ui-dashboard/commit/cb0e850c4c8cc0562afa39d01ef829ec48523ba9)

This update allows saving the Github user ID in the Users table ( oauth_github field) and binds the Users table to the OAuth context.

```python
# Truncated content

class Users(db.Model, UserMixin):

    id            = db.Column(db.Integer, primary_key=True)
    username      = db.Column(db.String(64), unique=True)
    email         = db.Column(db.String(64), unique=True)
    password      = db.Column(db.LargeBinary) 
    oauth_github  = db.Column(db.String(100), nullable=True)   # OAuth NEW
    
class OAuth(OAuthConsumerMixin, db.Model):                     # OAuth NEW  
    user_id = db.Column(db.Integer, db.ForeignKey("Users.id")) # OAuth NEW
    user = db.relationship(Users)                              # OAuth NEW
```

---

> 👉 `Flask OAuth` **Update Routes** - [GH commit](https://github.com/app-generator/flask-soft-ui-dashboard/commit/b5915172ee53e78cfc98ea515647ca57889c8e4e)

```python
@blueprint.route("/github")
def login_github(): 

    """ Github login """
    if not github.authorized:
        return redirect(url_for("github.login"))

    res = github.get("/user")
    return redirect(url_for('home_blueprint.index'))
```

---

> 👉 `Flask OAuth` **Register Github BP** - [GH commit](https://github.com/app-generator/flask-soft-ui-dashboard/commit/8bb8d61aba491815a4f7ff54885dcc5cdf416567)

```python
# Truncated content

from apps.authentication.oauth import github_blueprint           # OAuth NEW

def create_app(config):
    app = Flask(__name__)
    app.config.from_object(config)
    register_extensions(app)
    register_blueprints(app)

    app.register_blueprint(github_blueprint, url_prefix="/login") # OAuth NEW

    configure_database(app)
    return app 
```

---

> 👉 `Flask OAuth` **Enable GH Login Button** - [GH commit](https://github.com/app-generator/flask-soft-ui-dashboard/commit/4a4eff5c51e897e661fb0f2953b746907047ceb1)

```html
<!-- GitHub button starts here -->
{ % if config.SOCIAL_AUTH_GITHUB % }

  <p class="mb-2">or SignIn with</p>

  <a class="btn btn-outline" 
     href="{{url_for('authentication_blueprint.login_github')}}">
	<span class="text-lg fs-1 fab fa-github"></span>
  </a>

{ % endif % }
<!-- GitHub ends here -->
```

On the sign-in page, if the Github secrets are detected and loaded by the app config, the social login button is automatically enabled, as shown below: 

![Soft Dashboard - OAuth SignIN Active (Flask Starter)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jl8r5fhdpyt2w8ppmdh6.png)

--- 

![Soft Dashboard - Charts Page (Flask Starter)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kh5dk6ydywhpzyd0fcmv.png)

---

## ✨ Design Highlights

This UI Kit is crafted by [Creative-Tim](https://www.creative-tim.com/?AFFILIATE=128200) on top of Bootstrap 5 with 10 sample pages and 70+ UI components.  All components can take variations in color, that you can easily modify using SASS files and classes.

This Free Dashboard is coming with prebuilt design blocks, so the development process is seamless, and switching from our pages to the real website is very easy to be done.

For more information regarding this amazing design feel free to access the [official product page](https://www.creative-tim.com/product/soft-ui-dashboard?AFFILIATE=128200). 

![Soft UI Dashboard - Template Version by (Creative-Tim) ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ae4lwpgfyjcg5lv5jdxw.png)

---

> Thanks for reading! For more resources and support, please access:

- 👉 [Soft UI Dashboard Flask](https://appseed.us/product/soft-ui-dashboard/flask/) - product page
- 👉 Ask for [support](https://appseed.us/support/) or download [free starters](https://appseed.us/apps/open-source/)