- Notifications
You must be signed in to change notification settings - Fork 196
Add support for JWT Authentication #79
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -18,6 +18,7 @@ | |
| | ||
| from six import with_metaclass | ||
| from typing import Any, Optional, Text # NOQA | ||
| from requests.auth import AuthBase | ||
| Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's out of scope of this PR, but we should define an ALL here, so that | ||
| | ||
| | ||
| class Authentication(with_metaclass(abc.ABCMeta)): # type: ignore | ||
| | @@ -131,3 +132,38 @@ def get_exceptions(self): | |
| | ||
| def handle_error(self, handle_error): | ||
| pass | ||
| | ||
| | ||
| class _BearerAuth(AuthBase): | ||
| """ | ||
| Custom implementation of Authentication class for bearer token | ||
| """ | ||
| def __init__(self, token): | ||
| self.token = token | ||
| | ||
| def __call__(self, r): | ||
| r.headers["Authorization"] = "Bearer " + self.token | ||
| return r | ||
| | ||
| | ||
| class JWTAuthentication(Authentication): | ||
| | ||
| def __init__(self, token): | ||
| self.token = token | ||
| | ||
| def set_client_session(self, client_session): | ||
| pass | ||
| | ||
| def set_http_session(self, http_session): | ||
| http_session.auth = _BearerAuth(self.token) | ||
| return http_session | ||
| | ||
| def setup(self, trino_client): | ||
| self.set_client_session(trino_client.client_session) | ||
| self.set_http_session(trino_client.http_session) | ||
| | ||
| def get_exceptions(self): | ||
| return () | ||
| | ||
| def handle_error(self, handle_error): | ||
| pass | ||
| Comment on lines +165 to +169 Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is default behavior of Authentication, so seems can be omitted here | ||
Uh oh!
There was an error while loading. Please reload this page.