Skip to content

Commit 4e61be8

Browse files
ms32035ebyhr
authored andcommitted
Add JWT token support via connection string in sqlalchemy
1 parent a05f601 commit 4e61be8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,11 @@ the [`JWT` authentication type](https://trino.io/docs/current/security/jwt.html)
151151

152152
```python
153153
from sqlalchemy import create_engine
154-
from trino.auth import JWTAuthentication
155154

155+
engine = create_engine("trino://<username>@<host>:<port>/<catalog>/<schema>?access_token=<jwt_token>")
156+
157+
# or
158+
from trino.auth import JWTAuthentication
156159
engine = create_engine(
157160
"trino://<username>@<host>:<port>/<catalog>",
158161
connect_args={

trino/sqlalchemy/dialect.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from sqlalchemy.engine.url import URL
1919

2020
from trino import dbapi as trino_dbapi, logging
21-
from trino.auth import BasicAuthentication
21+
from trino.auth import BasicAuthentication, JWTAuthentication
2222
from trino.dbapi import Cursor
2323
from trino.exceptions import TrinoUserError
2424
from trino.sqlalchemy import compiler, datatype, error
@@ -87,6 +87,10 @@ def create_connect_args(self, url: URL) -> Tuple[Sequence[Any], Mapping[str, Any
8787
kwargs["http_scheme"] = "https"
8888
kwargs["auth"] = BasicAuthentication(url.username, url.password)
8989

90+
if "access_token" in url.query:
91+
kwargs["http_scheme"] = "https"
92+
kwargs["auth"] = JWTAuthentication(url.query["access_token"])
93+
9094
return args, kwargs
9195

9296
def get_columns(self, connection: Connection, table_name: str, schema: str = None, **kw) -> List[Dict[str, Any]]:

0 commit comments

Comments
 (0)