Skip to content

Commit

Permalink
added additional logging
Browse files Browse the repository at this point in the history
  • Loading branch information
P-T-I committed Jul 26, 2022
1 parent 876f49c commit 1647054
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5
2.6
2 changes: 1 addition & 1 deletion spectacles/webapp/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5
2.6
57 changes: 35 additions & 22 deletions spectacles/webapp/auth/openid_login.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import random

import requests
Expand All @@ -7,6 +8,11 @@
from spectacles.webapp.app.models import users, groups, groupmembers
from spectacles.webapp.run import db, oidc
from . import auth
from ...helpers.app_logger import AppLogger

logging.setLoggerClass(AppLogger)

logger = logging.getLogger(__name__)


@auth.route("/oidc_login")
Expand All @@ -17,6 +23,8 @@ def oidc_login():

info = oidc.user_getinfo(["trigram", "client_roles", "realm_roles", "groups"])

logger.info(f"Retrieved userinfo: {info}")

username = info.get("trigram", None)

username = username.lower()
Expand All @@ -37,6 +45,8 @@ def oidc_login():

account = users.query.filter_by(username=username).first()

logger.info(f"Got account: {account}")

if account:
# Check role and group accordingly; alter when needed and save to backend
if account.role != role:
Expand Down Expand Up @@ -89,25 +99,28 @@ def oidc_login():

def oidc_logout():

with requests.session() as session:

if oidc is not None:
headers = {
"Authorization": f"Bearer {oidc.get_access_token()}",
"Content-Type": "application/x-www-form-urlencoded",
}

data = {
"client_id": f"{oidc.client_secrets.get('client_id')}",
"client_secret": f"{oidc.client_secrets.get('client_secret')}",
"refresh_token": f"{oidc.get_refresh_token()}",
}

session.post(
url=f"{oidc.client_secrets.get('issuer')}/protocol/openid-connect/logout",
data=data,
headers=headers,
verify=False,
)

oidc.logout()
try:
with requests.session() as session:

if oidc is not None:
headers = {
"Authorization": f"Bearer {oidc.get_access_token()}",
"Content-Type": "application/x-www-form-urlencoded",
}

data = {
"client_id": f"{oidc.client_secrets.get('client_id')}",
"client_secret": f"{oidc.client_secrets.get('client_secret')}",
"refresh_token": f"{oidc.get_refresh_token()}",
}

session.post(
url=f"{oidc.client_secrets.get('issuer')}/protocol/openid-connect/logout",
data=data,
headers=headers,
verify=False,
)

oidc.logout()
except Exception:
raise
2 changes: 2 additions & 0 deletions spectacles/webapp/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def logout():
oidc_logout()
except ImportError:
pass
except Exception:
pass

# Redirect to login page
return redirect(url_for("auth.func_login"))
Expand Down
2 changes: 1 addition & 1 deletion spectacles/webapp/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def create_app(version):
app.config["SQLALCHEMY_POOL_TIMEOUT"] = 20

# Cache-control
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 300
app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 300

if not config.DEBUG:
app.config["SESSION_COOKIE_NAME"] = "spectacles.session"
Expand Down

0 comments on commit 1647054

Please sign in to comment.