To integrate OpenID authentication with our application, we are going to use a new Flask extension named Flask-OpenID, implemented by the Flask creator itself. As always, the extension needs to be added to the requirements.txt file, as follows:
...
Flask-OpenID
...
Our app will also need a couple of things to implement OpenID:
- A new form object
- The form validation in the login and registration pages
- A callback after the form submission to log the user in or create a new user
In the auth/__init__.py file, the OpenID object can be initialized as follows:
...
from flask_openid import OpenID
... oid = OpenID()
In the create_module function, the oid object is registered to the app object, as follows:
def create_module(app, **kwargs):
...
oid.init_app(app)
...
The new form object will only need the URL of the OpenID provider. In auth/forms.py, enter the following...