Skip to content

Commit

Permalink
Allow authentication over HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
koszti committed Feb 6, 2025
1 parent 1e95bbf commit f6cb973
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ It follows the interface for `KerberosAuthentication`, but is using
)
```


## User impersonation

In the case where user who submits the query is not the same as user who authenticates to Trino server (e.g in Superset),
Expand Down
10 changes: 0 additions & 10 deletions tests/unit/sqlalchemy/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def setup_method(self):
catalog="system",
user="user",
auth=BasicAuthentication("user", "pass"),
http_scheme="https",
source="trino-rulez"
),
),
Expand All @@ -80,7 +79,6 @@ def setup_method(self):
catalog="system",
user="user",
auth=CertificateAuthentication("/my/path/to/cert", "afdlsdfk%4#'"),
http_scheme="https",
source="trino-sqlalchemy"
),
),
Expand All @@ -100,7 +98,6 @@ def setup_method(self):
catalog="system",
user="user",
auth=JWTAuthentication("afdlsdfk%4#'"),
http_scheme="https",
source="trino-sqlalchemy"
),
),
Expand Down Expand Up @@ -168,7 +165,6 @@ def setup_method(self):
catalog="system",
user="[email protected]/my_role",
auth=BasicAuthentication("[email protected]/my_role", "pass /*&"),
http_scheme="https",
source="trino-sqlalchemy",
session_properties={"query_max_run_time": "1d"},
http_headers={"trino": 1},
Expand Down Expand Up @@ -270,7 +266,6 @@ def test_trino_connection_basic_auth():
url = make_url(f'trino://{username}:{password}@host')
_, cparams = dialect.create_connect_args(url)

assert cparams['http_scheme'] == "https"
assert isinstance(cparams['auth'], BasicAuthentication)
assert cparams['auth']._username == username
assert cparams['auth']._password == password
Expand All @@ -282,7 +277,6 @@ def test_trino_connection_jwt_auth():
url = make_url(f'trino://host/?access_token={access_token}')
_, cparams = dialect.create_connect_args(url)

assert cparams['http_scheme'] == "https"
assert isinstance(cparams['auth'], JWTAuthentication)
assert cparams['auth'].token == access_token

Expand All @@ -294,7 +288,6 @@ def test_trino_connection_certificate_auth():
url = make_url(f'trino://host/?cert={cert}&key={key}')
_, cparams = dialect.create_connect_args(url)

assert cparams['http_scheme'] == "https"
assert isinstance(cparams['auth'], CertificateAuthentication)
assert cparams['auth']._cert == cert
assert cparams['auth']._key == key
Expand All @@ -307,13 +300,11 @@ def test_trino_connection_certificate_auth_cert_and_key_required():
url = make_url(f'trino://host/?cert={cert}')
_, cparams = dialect.create_connect_args(url)

assert 'http_scheme' not in cparams
assert 'auth' not in cparams

url = make_url(f'trino://host/?key={key}')
_, cparams = dialect.create_connect_args(url)

assert 'http_scheme' not in cparams
assert 'auth' not in cparams


Expand All @@ -322,5 +313,4 @@ def test_trino_connection_oauth2_auth():
url = make_url('trino://host/?externalAuthentication=true')
_, cparams = dialect.create_connect_args(url)

assert cparams['http_scheme'] == "https"
assert isinstance(cparams['auth'], OAuth2Authentication)
2 changes: 0 additions & 2 deletions trino/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,6 @@ def __init__(
self._exceptions = self.HTTP_EXCEPTIONS
self._auth = auth
if self._auth:
if self._http_scheme == constants.HTTP:
raise ValueError("cannot use authentication with HTTP")
self._auth.set_http_session(self._http_session)
self._exceptions += self._auth.get_exceptions()

Expand Down
4 changes: 0 additions & 4 deletions trino/sqlalchemy/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,15 @@ def create_connect_args(self, url: URL) -> Tuple[Sequence[Any], Mapping[str, Any
if url.password:
if not url.username:
raise ValueError("Username is required when specify password in connection URL")
kwargs["http_scheme"] = "https"
kwargs["auth"] = BasicAuthentication(unquote_plus(url.username), unquote_plus(url.password))

if "access_token" in url.query:
kwargs["http_scheme"] = "https"
kwargs["auth"] = JWTAuthentication(unquote_plus(url.query["access_token"]))

if "cert" in url.query and "key" in url.query:
kwargs["http_scheme"] = "https"
kwargs["auth"] = CertificateAuthentication(unquote_plus(url.query['cert']), unquote_plus(url.query['key']))

if "externalAuthentication" in url.query:
kwargs["http_scheme"] = "https"
kwargs["auth"] = OAuth2Authentication()

if "source" in url.query:
Expand Down

0 comments on commit f6cb973

Please sign in to comment.