How to setup OpenID to work with load balancer? How to setup OpenID to work with load balancer? flask flask

How to setup OpenID to work with load balancer?


From the documentation

Note that you should probably provide the library with a place to store the credentials it has retrieved for the user. These need to be stored in a place where the user themselves or an attacker can not get to them. To provide this, give an object that has setitem and getitem dict APIs implemented as second argument to the init() call. Without this, the library will only work on a single thread, and only retain sessions until the server is restarted.

It is referring to credentials_store option in OpenIDConnect instantiation. To support persisted login via multiple application instances, you will need a persisted shared datastore for this use case. You could use a share redis or dynamodb instance.

Implementation of this credentials_store is fairly simple, you can try something like,

class RedisOpenIdCredStore:    def __init__(self):        # Handle Redis instance initialisation here        pass    def __setitem__(self, key, value):        # Set item to redis        pass    def __getitem__(self, key):        # Fetch and return item from redis if present        passcredential_store = RedisOpenIdCredStore()oid_connect = OpenIDConnect(app, credential_store=credential_store, ...)