@@ -252,7 +252,7 @@ The OAuth2 token will be cached either per `trino.auth.OAuth2Authentication` ins
252252 from trino.auth import OAuth2Authentication
253253
254254 engine = create_engine(
255- " trino://<username>@<host>:<port>/<catalog>" ,
255+ " trino://<username>@<host>:<port>/<catalog>" ,
256256 connect_args = {
257257 " auth" : OAuth2Authentication(),
258258 " http_scheme" : " https" ,
@@ -262,156 +262,84 @@ The OAuth2 token will be cached either per `trino.auth.OAuth2Authentication` ins
262262
263263# ### Client Credentials authentication
264264
265- The `ClientCredentials` class enables service- to- service authentication using standard OAuth2 Client Credentials flow.
266-
267- - DBAPI
268-
269- export KEYRING_CRYPTFILE_PASSWORD = password123
270-
271- ```python
272- from trino.dbapi import connect
273- from trino.auth import ClientCredentials, OidcConfig
274-
275- conn = connect(
276- user = " <username>" ,
277- auth = ClientCredentials(
278- client_id = " <client_id>" ,
279- client_secret = " <client_secret>" ,
280- url_config = OidcConfig(oidc_discovery_url = " <oidc_discovery_url>" )
281- ),
282- http_scheme = " https" ,
283- ...
284- )
285- ```
286-
287- Or using manual URLs:
288-
289- ```python
290- from trino.dbapi import connect
291- from trino.auth import ClientCredentials, ManualUrlsConfig
292-
293- conn = connect(
294- user = " <username>" ,
295- auth = ClientCredentials(
296- client_id = " <client_id>" ,
297- client_secret = " <client_secret>" ,
298- url_config = ManualUrlsConfig(token_endpoint = " <token_endpoint>" )
299- ),
300- http_scheme = " https" ,
301- ...
302- )
303- ```
304-
305- With optional `scope` and `audience` :
306-
307- ```python
308- from trino.dbapi import connect
309- from trino.auth import ClientCredentials, OidcConfig
265+ ```python
266+ from trino.dbapi import connect
267+ from trino.auth import ClientCredentials
268+ from trino.oauth2.models import OidcConfig
269+
270+ auth = ClientCredentials(
271+ client_id = " <client_id>" ,
272+ client_secret = " <client_secret>" ,
273+ url_config = OidcConfig(
274+ token_endpoint = " <token_endpoint>" ,
275+ # other endpoints if needed
276+ ),
277+ scope = " <number of scopes>" , # optional
278+ audience = " <audience>" , # optional
279+ )
310280
311- conn = connect(
312- user = " <username>" ,
313- auth = ClientCredentials(
314- client_id = " <client_id>" ,
315- client_secret = " <client_secret>" ,
316- scope = " <scope>" ,
317- audience = " <audience>" ,
318- url_config = OidcConfig(oidc_discovery_url = " <oidc_discovery_url>" )
319- ),
320- http_scheme = " https" ,
321- ...
322- )
323- ```
281+ conn = connect(
282+ user = " <username>" ,
283+ auth = auth,
284+ http_scheme = " https" ,
285+ ...
286+ )
287+ ```
324288
325289#### Device Code authentication
326290
327- The `DeviceCode` class enables authentication on devices with limited input capabilities using OAuth2 Device Code flow.
328- This flow prints tries to open an browser to the URL but it will also fall back and print the verification code and
329- a URL to visit on another device to authenticate.
330-
331- - DBAPI
332-
333- export KEYRING_CRYPTFILE_PASSWORD = password123
334-
335- ```python
336- from trino.dbapi import connect
337- from trino.auth import DeviceCode, OidcConfig
338-
339- conn = connect(
340- user = " <username>" ,
341- auth = DeviceCode(
342- client_id = " <client_id>" ,
343- client_secret = " <client_secret>" ,
344- url_config = OidcConfig(oidc_discovery_url = " <oidc_discovery_url>" )
345- ),
346- http_scheme = " https" ,
347- ...
348- )
349- ```
350-
351- With optional `scope` and `audience` :
352-
353- ```python
354- from trino.dbapi import connect
355- from trino.auth import DeviceCode, OidcConfig
291+ ``` python
292+ from trino.dbapi import connect
293+ from trino.auth import DeviceCode
294+ from trino.oauth2.models import OidcConfig
295+
296+ auth = DeviceCode(
297+ client_id = " <client_id>" ,
298+ url_config = OidcConfig(
299+ token_endpoint = " <token_endpoint>" ,
300+ device_authorization_endpoint = " <device_authorization_endpoint>" ,
301+ ),
302+ scope = " <scope>" , # optional
303+ audience = " <audience>" , # optional
304+ )
356305
357- conn = connect(
358- user = " <username>" ,
359- auth = DeviceCode(
360- client_id = " <client_id>" ,
361- client_secret = " <client_secret>" ,
362- scope = " <scope>" ,
363- audience = " <audience>" ,
364- url_config = OidcConfig(oidc_discovery_url = " <oidc_discovery_url>" )
365- ),
366- http_scheme = " https" ,
367- ...
368- )
369- ```
306+ conn = connect(
307+ user = " <username>" ,
308+ auth = auth,
309+ http_scheme = " https" ,
310+ ...
311+ )
312+ ```
370313
371314#### Authorization Code authentication
372315
373- The `AuthorizationCode` class enables the standard OAuth2 Authorization Code flow.
374-
375- - DBAPI
376-
377- export KEYRING_CRYPTFILE_PASSWORD = password123
378-
379- ```python
380- from trino.dbapi import connect
381- from trino.auth import AuthorizationCode, OidcConfig
382-
383- conn = connect(
384- user = " <username>" ,
385- auth = AuthorizationCode(
386- client_id = " <client_id>" ,
387- client_secret = " <client_secret>" ,
388- url_config = OidcConfig(oidc_discovery_url = " <oidc_discovery_url>" )
389- ),
390- http_scheme = " https" ,
391- ...
392- )
393- ```
394-
395- With optional `scope` and `audience` :
316+ ``` python
317+ from trino.dbapi import connect
318+ from trino.auth import AuthorizationCode
319+ from trino.oauth2.models import OidcConfig
320+
321+ auth = AuthorizationCode(
322+ client_id = " <client_id>" ,
323+ client_secret = " <client_secret>" , # optional
324+ url_config = OidcConfig(
325+ token_endpoint = " <token_endpoint>" ,
326+ authorization_endpoint = " <authorization_endpoint>" ,
327+ ),
328+ scope = " <scope>" , # optional
329+ audience = " <audience>" , # optional
330+ )
396331
397- ```python
398- from trino.dbapi import connect
399- from trino.auth import AuthorizationCode, OidcConfig
332+ conn = connect(
333+ user = " <username>" ,
334+ auth = auth,
335+ http_scheme = " https" ,
336+ ...
337+ )
338+ ```
400339
401- conn = connect(
402- user = " <username>" ,
403- auth = AuthorizationCode(
404- client_id = " <client_id>" ,
405- client_secret = " <client_secret>" ,
406- scope = " <scope>" ,
407- audience = " <audience>" ,
408- url_config = OidcConfig(oidc_discovery_url = " <oidc_discovery_url>" )
409- ),
410- http_scheme = " https" ,
411- ...
412- )
413- ```
340+ ### Reference
414341
342+ For further details, please consult [ Trino documentation] ( https://trino.io/docs/current ) .
415343
416344### Secure Token Storage
417345
0 commit comments