Snippets are unofficial and unmaintained.
This is an archived view of user-submitted snippets. Despite being hosted on the Flask site, they are not official. No Flask maintainer has curated or checked the snippets for security, correctness, or design.
There is a Flask Addon Library called Flask-OpenID that implements basic OpenID authentication for Flask on top of python-openid.
The included example shows how this can be done. Basically all you need to do is this:
OpenIDwith the path to the stored files. This can be any folder on the filesystem,
OpenIDwill use it to store temporary information required for the authentication process.
loginhandlerfunction. That function has to render the form and call into
try_loginwith the submitted identity URL (the OpenID the user entered).
after_loginfunction. This function is called with the identity URL if authentication worked. This function must redirect to a different page. It usually checks if the user is known to the system and if this is the case, logs the user in or otherwise redirects to a page used to create that profile.
If that is too abstract, look at the example for more information about how to use it.
Note that Flask-OpenID also has basic support for redirections, so the user will after login end up on the page where he or she previously was. For the redirections to work, it is necessary to have the forms forward the
next parameter properly. Make sure to have a look at the template code as well.
Also check out the website for more information and a detailed documentation: Flask-OpenID
This snippet by Armin Ronacher can be used freely for anything you like. Consider it public domain.