Fix OIDC id_token parsing

Unbreak it, actually.
This commit is contained in:
Timotej Lazar 2023-09-11 15:10:19 +02:00
parent 719bcf7c55
commit ea6aa37131

View file

@ -10,10 +10,10 @@ auth = None
users = {} users = {}
class User(flask_login.UserMixin): class User(flask_login.UserMixin):
def __init__(self, userinfo): def __init__(self, info):
self.username = userinfo['preferred_username'] self.username = info.get('preferred_username', '')
self.groups = set(userinfo.get('groups', ())) self.groups = set(info.get('groups', ()))
self.data = userinfo self.data = info # for debugging really
try: try:
self.is_admin = db.load('settings').get('admin_group') in self.groups self.is_admin = db.load('settings').get('admin_group') in self.groups
except: except:
@ -51,7 +51,7 @@ def init_app(app):
@app.route('/auth') @app.route('/auth')
def auth(): def auth():
token = oauth.azure.authorize_access_token() token = oauth.azure.authorize_access_token()
user = users[user.username] = User(oauth.azure.parse_id_token(token)) user = users[user.username] = User(token.get('userinfo', {}))
flask_login.login_user(user) flask_login.login_user(user)
return flask.redirect('/') return flask.redirect('/')