Skip to content

Commit 0a51aac

Browse files
pini-ghvsoch
andauthored
API token: support any casing for 'Bearer' (#343)
* API token: support any casing for 'Bearer' Fixes #342 * running black formatting, version bump Signed-off-by: vsoch <vsoch@users.noreply.github.com> Co-authored-by: vsoch <vsoch@users.noreply.github.com>
1 parent 3fbea05 commit 0a51aac

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ represented by the pull requests that fixed them. Critical items to know are:
1212

1313

1414
## [master](https://github.com/singularityhub/sregistry/tree/master) (master)
15+
- allowing for Bearer token to have any casing (1.1.31)
1516
- adding minio environment file to https docker-compose (1.1.3)
1617
- enforcing usernames to be all lowercase (1.1.29)
1718
- Added ability to specify Minio direct download from interface (1.1.28)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.3
1+
1.1.31

shub/apps/library/views/helpers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ def validate_token(request):
3131
token = request.META.get("HTTP_AUTHORIZATION")
3232
if token:
3333
try:
34-
token = token.split(" ")[-1] # Get rid of BEARER or Bearer <token>
35-
Token.objects.get(key=token.strip())
34+
Token.objects.get(
35+
key=re.sub("bearer", "", token, flags=re.IGNORECASE).strip()
36+
)
3637
return True
3738
except Token.DoesNotExist:
3839
pass
@@ -48,7 +49,9 @@ def get_token(request):
4849

4950
if token:
5051
try:
51-
return Token.objects.get(key=token.replace("BEARER", "").strip())
52+
return Token.objects.get(
53+
key=re.sub("bearer", "", token, flags=re.IGNORECASE).strip()
54+
)
5255
except Token.DoesNotExist:
5356
pass
5457

0 commit comments

Comments
 (0)