Flask Mega-Tutorial: Converting OpenID to OAuth

With this blog post I hope to provide some help to those who are trying to combine Miguel Grinberg’s Flask Mega Tutorial with his other tutorial titled OAuth Authentication with Flask.  I have a repo that has a working version of his Mega Tutorial through chapter 5 that uses OAuth instead of OpenID.  You can find it here https://github.com/JasonMFry/Flask-Mega-Tutorial-With-OAuth (there are known bugs that will occur as you move further into the Mega Tutorial, and I will list them in the github issues).  I have made some comments in the code that help explain why some code needs to be changed.  And for reference I have commented out (instead of deleted) all OpenID references that are no longer needed.

As a quick and brief explanation, the code in flask-oauth-example/app.py (from his OAuth tutorial) gets divided up into config.pyapp/__init__.py, app/models.py, and app/views.py (from his Mega Tutorial).  The oauth.py file (from OAuth tutorial) goes directly into the app/ directory.  The code in flask-oauth-example/templates/index.html (from OAuth tutorial) replaces most of the code in app/templates/login.html (from Mega Tutorial).  Your directory structure will look like this:

| |______init__.py
| |____forms.py
| |____models.py
| |____oauth.py
| |____templates
| | |____base.html
| | |____index.html
| | |____login.html
| |____views.py

You will also have a db_repository directory but that was adding unnecessary info to the above directory structure so I removed it.  But I mention this so you don’t get confused.  I hope you are able to follow his two tutorials, and compare your code to mine to get yours working.  Good luck, and sound off in the comments below if you need some help.


1 thought on “Flask Mega-Tutorial: Converting OpenID to OAuth

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s