Update main.py
This commit is contained in:
parent
dd1f43a70e
commit
416b6d4a65
|
@ -77,21 +77,23 @@ def main():
|
||||||
self.proxy()
|
self.proxy()
|
||||||
|
|
||||||
def _validate_user_and_key(self):
|
def _validate_user_and_key(self):
|
||||||
# Extract the bearer token from the headers
|
try:
|
||||||
auth_header = self.headers.get('Authorization')
|
# Extract the bearer token from the headers
|
||||||
if not auth_header or not auth_header.startswith('Bearer '):
|
auth_header = self.headers.get('Authorization')
|
||||||
|
if not auth_header or not auth_header.startswith('Bearer '):
|
||||||
|
return False
|
||||||
|
token = auth_header.split(' ')[1]
|
||||||
|
user, key = token.split(':')
|
||||||
|
|
||||||
|
# Check if the user and key are in the list of authorized users
|
||||||
|
if authorized_users.get(user) == key:
|
||||||
|
self.user = user
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
self.user = "unknown"
|
||||||
return False
|
return False
|
||||||
token = auth_header.split(' ')[1]
|
except:
|
||||||
user, key = token.split(':')
|
|
||||||
|
|
||||||
# Check if the user and key are in the list of authorized users
|
|
||||||
if authorized_users.get(user) == key:
|
|
||||||
self.user = user
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
self.user = "unknown"
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def proxy(self):
|
def proxy(self):
|
||||||
if not self._validate_user_and_key():
|
if not self._validate_user_and_key():
|
||||||
ASCIIColors.red(f'User is not authorized')
|
ASCIIColors.red(f'User is not authorized')
|
||||||
|
|
Loading…
Reference in New Issue