Added authenticator hook for synchronizing user groups

- Added hook function stub to authenticator base class
- Added new config option `manage_groups` to base `Authenticator` class
- Call authenticator hook from `refresh_auth`-function in `Base` handler class
- Added example
This commit is contained in:
Thomas Li Fredriksen
2021-07-23 14:32:44 +02:00
committed by Min RK
parent dcf21d53fd
commit 144abcb965
7 changed files with 88 additions and 0 deletions

View File

@@ -253,6 +253,19 @@ class User:
def spawner_class(self):
return self.settings.get('spawner_class', LocalProcessSpawner)
def sync_groups(self, user_groups):
"""Syncronize groups with database"""
if user_groups:
groups = (
self.db.query(orm.Group).filter(orm.Group.name.in_(user_groups)).all()
)
groups = {g.name: g for g in groups}
self.groups = [groups.get(g, orm.Group(name=g)) for g in user_groups]
else:
self.groups = []
async def save_auth_state(self, auth_state):
"""Encrypt and store auth_state"""
if auth_state is None: