Originally published at https://www.viktorroytman.com/blog/2017/02/15/a-library -for-portier-with-asyncio/
In a previous post, I said:
Down the line, there will be client-side Portier libraries (or, at least, other demo implementations) for various languages. Until then, you’ll need to do some of the heavy lifting yourself.
The asyncio-portier library works with Python 3.5 and up.
There’s a functioning demo included with the library which you can use as a template. I’ll go into more detail about it here.
If you’ve read the previous post, this should seem pretty familiar. There are a few important differences though; I’ll point them out along the way.
The login endpoint
cacheis a Redis connection object as from redis-py
self.audienceis the URL of your application (such as
broker_urlis the URL of the Portier Broker,
The primary difference here is in what we set in the Redis cache. We prepend
'portier:nonce:' to the nonce value used for the key, and we set
the value to the
next URL query parameter. With this, if the user visits a
page that requires authentication, the application can redirect them directly
to that page after they have logged in.
The verify endpoint
- You have a template for an error page named
get_verified_email function now takes a number of explicit parameters
instead of reading from a global
SETTINGS object. It can raise
RuntimeError. It also now returns a
next_page in addition to an
This library should make things a little bit easier for anyone using Portier and asyncio. Please let me know if you run into any issues!