Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add custom X-IRIS-AUTH header #506

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions source/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,22 @@ def load_user_from_request(request):

# first, try to login using the api_key url arg
api_key = request.args.get('api_key')
if api_key:
user = User.query.filter(
User.api_key == api_key,
User.active == True
).first()
if user:
return user

# next, try to login using Basic Auth
api_key = request.headers.get('Authorization')
if api_key:
api_key = api_key.replace('Bearer ', '', 1)
if not api_key:
api_key = request.headers.get('Authorization')

user = User.query.filter(
User.api_key == api_key,
User.active == True
).first()
# next, try to login using Basic Auth from custom Header
if not api_key:
api_key = request.headers.get('X-IRIS-AUTH')

if user:
return user
if not api_key:
return None

# finally, return None if both methods did not login the user
return None
api_key = api_key.replace('Bearer ', '', 1)
user = User.query.filter(
User.api_key == api_key,
User.active == True
).first()

return user