Token tweaks (#6354)

- Adjust to allow "bearer" token type
This commit is contained in:
Oliver 2024-01-29 15:58:56 +11:00 committed by GitHub
parent cf7a20e1b7
commit b42f8a620b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,6 +21,7 @@ logger = logging.getLogger('inventree')
def get_token_from_request(request):
"""Extract token information from a request object."""
auth_keys = ['Authorization', 'authorization']
token_keys = ['token', 'bearer']
token = None
@ -28,7 +29,8 @@ def get_token_from_request(request):
if auth_header := request.headers.get(k, None):
auth_header = auth_header.strip().lower().split()
if len(auth_header) > 1 and auth_header[0].startswith('token'):
if len(auth_header) > 1:
if auth_header[0].strip().lower().replace(':', '') in token_keys:
token = auth_header[1]
break