-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supercoder Issue 1358 Resolved (#1426)
* Update user.py issue 1358 * Update auth.py issue 1358
- Loading branch information
1 parent
6c816d2
commit 24578a8
Showing
2 changed files
with
27 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,20 +44,28 @@ def get_user_organisation(Authorize: AuthJWT = Depends(check_auth)): | |
return organisation | ||
|
||
|
||
def get_current_user(Authorize: AuthJWT = Depends(check_auth)): | ||
def get_current_user(Authorize: AuthJWT = Depends(check_auth), request: Request = Depends()): | ||
env = get_config("ENV", "DEV") | ||
|
||
if env == "DEV": | ||
email = "[email protected]" | ||
else: | ||
# Retrieve the email of the logged-in user from the JWT token payload | ||
email = Authorize.get_jwt_subject() | ||
# Check for HTTP basic auth headers | ||
auth_header = request.headers.get('Authorization') | ||
if auth_header and auth_header.startswith('Basic '): | ||
import base64 | ||
auth_decoded = base64.b64decode(auth_header.split(' ')[1]).decode('utf-8') | ||
username, password = auth_decoded.split(':') | ||
# Assuming username is the email | ||
email = username | ||
else: | ||
# Retrieve the email of the logged-in user from the JWT token payload | ||
email = Authorize.get_jwt_subject() | ||
|
||
# Query the User table to find the user by their email | ||
user = db.session.query(User).filter(User.email == email).first() | ||
return user | ||
|
||
|
||
api_key_header = APIKeyHeader(name="X-API-Key") | ||
|
||
|
||
|
@@ -83,4 +91,4 @@ def get_organisation_from_api_key(api_key: str = Security(api_key_header)) -> Or | |
) | ||
|
||
organisation = db.session.query(Organisation).filter(Organisation.id == query_result.org_id).first() | ||
return organisation | ||
return organisation |