Do not store UGent username since it is not exposed through Graph API

This commit is contained in:
Maxim De Clercq 2023-04-19 22:03:40 +02:00
parent 6bb11e49a3
commit 1ffcdc3ec1
No known key found for this signature in database
GPG key ID: D35643779C52BA70
3 changed files with 5 additions and 15 deletions

View file

@ -8,22 +8,22 @@ import typing
from datetime import datetime
from logging.handlers import TimedRotatingFileHandler
from admin import init_admin
from flask import Flask, render_template
from flask_bootstrap import Bootstrap, StaticCDN
from flask_debugtoolbar import DebugToolbarExtension
from flask_login import LoginManager
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager, Server
from auth.login import init_login
from markupsafe import Markup
from admin import init_admin
from auth.login import init_login
from auth.zeus import init_oauth
from config import Configuration
from models import db
from models.anonymous_user import AnonymouseUser
from sentry_sdk.integrations.flask import FlaskIntegration
from utils import euro_string, price_range_string, ignore_none
from auth.zeus import init_oauth
def register_plugins(app: Flask) -> Manager:

View file

@ -36,25 +36,16 @@ def authorized() -> typing.Any:
oauth_code = request.args['code']
resp = client.exchange_code(url_for("auth_microsoft_bp.authorized", _external=True), oauth_code)
# access_token = resp.data['access_token']
# id_token = resp.data['id_token']
# expires_in = resp.data['expires_in']
client.set_token(resp.data)
resp = client.users.get_me()
# print(resp.data)
username = resp.data['userPrincipalName']
microsoft_uuid = resp.data['id']
user = User.query.filter_by(username=username).first()
if username and user:
return login_and_redirect_user(user)
elif username:
# TODO Save 'ugent_username' or something similar
user = create_user(username, microsoft_uuid)
return login_and_redirect_user(user)
@ -71,7 +62,7 @@ def login_and_redirect_user(user) -> Response:
def create_user(username, microsoft_uuid) -> User:
"""Create a temporary user if it is needed"""
user = User()
user.configure(username, False, 1, microsoft_uuid)
user.configure(username, False, 1, microsoft_uuid=microsoft_uuid)
db.session.add(user)
db.session.commit()
return user

View file

@ -12,7 +12,6 @@ class User(db.Model):
bias = db.Column(db.Integer)
# Microsoft OAUTH info
microsoft_uuid = db.Column(db.String(120), unique=True)
ugent_username = db.Column(db.String(80), unique=True)
# Association logic
associations = db.Column(db.String(255), nullable=False, server_default="")
@ -28,7 +27,7 @@ class User(db.Model):
def association_list(self) -> List[str]:
return self.associations.split(",")
def configure(self, username: str, admin: bool, bias: int, microsoft_uuid: str = None, associations: Optional[List[str]] = None) -> None:
def configure(self, username: str, admin: bool, bias: int, *, microsoft_uuid: str = None, associations: Optional[List[str]] = None) -> None:
"""Configure the User"""
if associations is None:
associations = []