mirror of
https://github.com/sartography/uva-covid19-testing-communicator.git
synced 2025-02-23 12:28:26 +00:00
provide some deatils on the current user. Assure we can get them consistently.
This commit is contained in:
parent
c17a18ab4a
commit
360d20560b
@ -14,6 +14,8 @@ from flask_sqlalchemy import SQLAlchemy
|
||||
from sentry_sdk.integrations.flask import FlaskIntegration
|
||||
from webassets import Bundle
|
||||
|
||||
from communicator.services.user_service import UserService
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
# API, fully defined in api.yml
|
||||
@ -149,14 +151,9 @@ def list_imported_files_from_ivy():
|
||||
|
||||
@app.route('/sso')
|
||||
def sso():
|
||||
user = UserService().get_user_info()
|
||||
response = ""
|
||||
response += "<h1>Headers</h1>"
|
||||
response += "<ul>"
|
||||
for k, v in request.headers:
|
||||
response += "<li><b>%s</b> %s</li>\n" % (k, v)
|
||||
response += "<h1>Environment</h1>"
|
||||
for k, v in request.environ:
|
||||
response += "<li><b>%s</b> %s</li>\n" % (k, v)
|
||||
response += f"<h1>Current User: {user.display_name} ({user.uid})</h1>"
|
||||
return response
|
||||
|
||||
# Access tokens
|
||||
|
5
communicator/models/user.py
Normal file
5
communicator/models/user.py
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
class User:
|
||||
def __init__(self, uid, display_name):
|
||||
self.uid = uid
|
||||
self.display_name = display_name
|
34
communicator/services/user_service.py
Normal file
34
communicator/services/user_service.py
Normal file
@ -0,0 +1,34 @@
|
||||
from flask import request
|
||||
|
||||
from communicator.errors import CommError
|
||||
from communicator.models.user import User
|
||||
|
||||
|
||||
class UserService(object):
|
||||
"""Provides details about the current User as read in from Shibboleth headers """
|
||||
# ----------------------------------------
|
||||
# Shibboleth Authentication Headers
|
||||
# ----------------------------------------
|
||||
# X-Remote-Cn: Daniel Harold Funk (dhf8r)
|
||||
# X-Remote-Sn: Funk
|
||||
# X-Remote-Givenname: Daniel
|
||||
# X-Remote-Uid: dhf8r
|
||||
# Eppn: dhf8r@virginia.edu
|
||||
# Cn: Daniel Harold Funk (dhf8r)
|
||||
# Sn: Funk
|
||||
# Givenname: Daniel
|
||||
# Uid: dhf8r
|
||||
# X-Remote-User: dhf8r@virginia.edu
|
||||
# X-Forwarded-For: 128.143.0.10
|
||||
# X-Forwarded-Host: dev.crconnect.uvadcos.io
|
||||
# X-Forwarded-Server: dev.crconnect.uvadcos.io
|
||||
# Connection: Keep-Alive
|
||||
|
||||
def get_user_info(self):
|
||||
uid = request.headers.get("Uid")
|
||||
cn = request.headers.get("Cn")
|
||||
if not uid:
|
||||
uid = request.headers.get("X-Remote-Uid")
|
||||
if not uid:
|
||||
raise CommError(1100, "invalid_sso_credentials", r"'Uid' nor 'X-Remote-Uid' were present in the headers: %s"% str(request.headers))
|
||||
return User(uid, cn)
|
Loading…
x
Reference in New Issue
Block a user