Skip to content

Commit 4d1aaa5

Browse files
authored
Merge pull request #346 from galenguyer/host-redirect
Redirect to the configured host before OIDC if incorrect
2 parents 1989bdf + c12d91a commit 4d1aaa5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packet/utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
from datetime import datetime, time, timedelta, date
55
from functools import wraps, lru_cache
66
from typing import Any, Callable, TypeVar, cast
7+
from urllib.parse import urlparse
78

89
import requests
9-
from flask import session, redirect
10+
from flask import session, redirect, request
1011

1112
from packet import auth, app, db, ldap
1213
from packet.mail import send_start_packet_mail
@@ -64,6 +65,16 @@ def is_freshman_on_floor(rit_username: str) -> bool:
6465
return False
6566

6667

68+
@app.before_request
69+
def before_reqest_callback() -> Any:
70+
"""
71+
Pre-request function to ensure we're on the right URL before OIDC sees anything
72+
"""
73+
if urlparse(request.base_url).hostname != app.config['SERVER_NAME']:
74+
return redirect(request.base_url.replace(urlparse(request.base_url).hostname,
75+
app.config['SERVER_NAME']), code=302)
76+
return None
77+
6778
def packet_auth(func: WrappedFunc) -> WrappedFunc:
6879
"""
6980
Decorator for easily configuring oidc

0 commit comments

Comments
 (0)