Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix www-authenticate header parsing bug when refreshing tokens #485

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions tests/unit/oauth_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,25 @@ def __call__(self, request, uri, response_headers):
if authorization and authorization.replace("Bearer ", "") in self.tokens:
return [200, response_headers, json.dumps(self.sample_post_response_data)]
elif self.redirect_server is None and self.token_server is not None:
return [401, {'Www-Authenticate': f'Bearer x_token_server="{self.token_server}"',
'Basic realm': '"Trino"'}, ""]
return [401, {'Www-Authenticate': f'Bearer x_redirect_server="{self.redirect_server}", '
f'x_token_server="{self.token_server}"',
'Basic realm': '"Trino"'}, ""]
return [401,
{
'Www-Authenticate': (
'Bearer realm="Trino", token_type="JWT", '
f'Bearer x_token_server="{self.token_server}"'
),
'Basic realm': '"Trino"'
},
""]
return [401,
{
'Www-Authenticate': (
'Bearer realm="Trino", token_type="JWT", '
f'Bearer x_redirect_server="{self.redirect_server}", '
f'x_token_server="{self.token_server}"'
),
'Basic realm': '"Trino"'
},
""]


class GetTokenCallback:
Expand Down
2 changes: 1 addition & 1 deletion trino/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def _attempt_oauth(self, response: Response, **kwargs: Any) -> None:
auth_info_headers = self._parse_authenticate_header(auth_info)

auth_server = auth_info_headers.get('bearer x_redirect_server', auth_info_headers.get('x_redirect_server'))
token_server = auth_info_headers.get('x_token_server')
token_server = auth_info_headers.get('bearer x_token_server', auth_info_headers.get('x_token_server'))
if token_server is None:
raise exceptions.TrinoAuthError("Error: header info didn't have x_token_server")

Expand Down