Skip to content

Commit 001a0b9

Browse files
committed
Issue #47 Remove 0.4-style basic auth bearer prefix
1 parent 5c6e374 commit 001a0b9

File tree

2 files changed

+2
-13
lines changed

2 files changed

+2
-13
lines changed

openeo_driver/users/auth.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ class OidcProviderUnavailableException(OpenEOApiException):
3333
class HttpAuthHandler:
3434
"""Handler for processing HTTP authentication in a Flask app context"""
3535

36-
# Access token prefix for 0.4-style basic auth
37-
# TODO: get rid of this prefix once 0.4 support is not necessary anymore
38-
_BASIC_ACCESS_TOKEN_PREFIX = 'basic.'
39-
4036
def __init__(
4137
self,
4238
oidc_providers: List[OidcProvider],
@@ -112,10 +108,6 @@ def get_user_from_bearer_token(self, request: flask.Request) -> User:
112108

113109
def _get_user_from_bearer_token(self, bearer: str) -> User:
114110
"""Get User object from bearer token of request."""
115-
# Support for 0.4-style basic auth
116-
if bearer.startswith(self._BASIC_ACCESS_TOKEN_PREFIX):
117-
return self.resolve_basic_access_token(access_token=bearer)
118-
# 1.0-style basic and OIDC auth
119111
try:
120112
bearer_type, provider_id, access_token = bearer.split('/')
121113
except ValueError:
@@ -165,14 +157,11 @@ def authenticate_basic(self, request: flask.Request) -> Tuple[str, str]:
165157
@staticmethod
166158
def build_basic_access_token(user_id: str) -> str:
167159
# TODO: generate real access token and link to user in some key value store
168-
prefix = HttpAuthHandler._BASIC_ACCESS_TOKEN_PREFIX
169-
return prefix + base64.urlsafe_b64encode(user_id.encode('utf-8')).decode('ascii')
160+
return base64.urlsafe_b64encode(user_id.encode("utf-8")).decode("ascii")
170161

171162
def resolve_basic_access_token(self, access_token: str) -> User:
172163
try:
173164
# Resolve token to user id
174-
head, _, access_token = access_token.partition(self._BASIC_ACCESS_TOKEN_PREFIX)
175-
assert head == '' and len(access_token) > 0
176165
user_id = base64.urlsafe_b64decode(access_token.encode('ascii')).decode('utf-8')
177166
except Exception:
178167
raise TokenInvalidException

tests/users/test_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_bearer_auth_basic_invalid_token(app, url):
160160
@pytest.mark.parametrize("url", ["/private/hello", "/personal/hello"])
161161
def test_bearer_auth_basic_invalid_token_prefix(app, url):
162162
with app.test_client() as client:
163-
headers = {"Authorization": "Bearer basic//{p}blehrff".format(p=HttpAuthHandler._BASIC_ACCESS_TOKEN_PREFIX)}
163+
headers = {"Authorization": "Bearer basic//blehrff"}
164164
response = client.get(url, headers=headers)
165165
assert_invalid_token_failure(response)
166166

0 commit comments

Comments
 (0)