Skip to content

Commit 3a13440

Browse files
Added support for token authentication (Azure OAuth and IAM) via the new
parameter "access_token" to oracledb.connect() and oracledb.create_pool().
1 parent 6a0fe94 commit 3a13440

28 files changed

+1103
-103
lines changed

doc/src/api_manual/connect_param.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ ConnectParams Methods
3333
that are found in the connect string override any currently stored values.
3434

3535
.. method:: ConnectParams.set(user=None, proxy_user=None, password=None, \
36-
newpassword=None, wallet_password=None, host=None, port=None, protocol=None, \
37-
https_proxy=None, https_proxy_port=None, service_name=None, sid=None, \
38-
server_type=None, cclass=None, purity=None, expire_time=None, retry_count=None, \
36+
newpassword=None, wallet_password=None, access_token=None, host=None, \
37+
port=None, protocol=None, https_proxy=None, https_proxy_port=None, service_name=None, \
38+
sid=None, server_type=None, cclass=None, purity=None, expire_time=None, retry_count=None, \
3939
retry_delay=None, tcp_connect_timeout=None, ssl_server_dn_match=None, \
4040
ssl_server_cert_dn=None, wallet_location=None, events=None, externalauth=None, \
4141
mode=None, disable_oob=None, stmtcachesize=None, edition=None, tag=None, \

doc/src/api_manual/module.rst

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ Oracledb Methods
4848
This method is an extension to the DB API definition.
4949

5050
.. function:: connect(dsn=None, pool=None, conn_class=None, params=None, user=None, \
51-
proxy_user=None, password=None, newpassword=None, wallet_password=None, \
51+
proxy_user=None, password=None, newpassword=None, wallet_password=None, access_token=None, \
5252
host=None, port=1521, protocol="tcp", https_proxy=None, https_proxy_port=0, \
5353
service_name=None, sid=None, server_type=None, cclass=None, purity=oracledb.PURITY_DEFAULT, \
5454
expire_time=0, retry_count=0, retry_delay=0, tcp_connect_timeout=60.0, \
55-
ssl_server_dn_match=True, ssl_server_cert_dn=None, wallet_location=None, \
56-
events=False, externalauth=False, mode=oracledb.AUTH_MODE_DEFAULT, disable_oob=False, \
55+
ssl_server_dn_match=True, ssl_server_cert_dn=None, wallet_location=None, events=False, \
56+
externalauth=False, mode=oracledb.AUTH_MODE_DEFAULT, disable_oob=False, \
5757
stmtcachesize=oracledb.defaults.stmtcachesize, edition=None, tag=None, matchanytag=False, \
5858
config_dir=oracledb.defaults.config_dir, appcontext=[], shardingkey=[], supershardingkey=[], \
5959
debug_jdwp=None, handle=0)
@@ -125,6 +125,17 @@ Oracledb Methods
125125
is not needed for cwallet.sso files that are used in the python-oracledb Thick
126126
mode.
127127

128+
The ``access_token`` parameter is expected to be a string or a 2-tuple or
129+
a callable. If it is a string, it specifies an Azure AD OAuth2 token used
130+
for Open Authorization (OAuth 2.0) token based authentication. If it is a
131+
2-tuple, it specifies the token and private key strings used for Oracle
132+
Cloud Infrastructure (OCI) Identity and Access Management (IAM) token based
133+
authentication. If it is a callable, it returns either a string or a 2-tuple
134+
used for OAuth 2.0 or OCI IAM token based authentication and is useful when
135+
the pool needs to expand and create new connections but the current
136+
authentication token has expired. This value is used in both the
137+
python-oracledb Thin and Thick modes.
138+
128139
The ``host`` parameter is expected to be a string which specifies the name or IP
129140
address of the machine hosting the listener, which handles the initial
130141
connection to the database. This value is used in both the python-oracledb
@@ -285,9 +296,9 @@ Oracledb Methods
285296
should be used with extreme caution. The default value is 0.
286297

287298
.. function:: ConnectParams(user=None, proxy_user=None, password=None, \
288-
newpassword=None, wallet_password=None, host=None, port=1521, protocol="tcp", \
289-
https_proxy=None, https_proxy_port=0, service_name=None, sid=None, \
290-
server_type=None, cclass=None, purity=oracledb.PURITY_DEFAULT, expire_time=0, \
299+
newpassword=None, wallet_password=None, access_token=None, host=None, \
300+
port=1521, protocol="tcp", https_proxy=None, https_proxy_port=0, service_name=None, \
301+
sid=None, server_type=None, cclass=None, purity=oracledb.PURITY_DEFAULT, expire_time=0, \
291302
retry_count=0, retry_delay=0, tcp_connect_timeout=60.0, ssl_server_dn_match=True, \
292303
ssl_server_cert_dn=None, wallet_location=None, events=False, externalauth=False, \
293304
mode=oracledb.AUTH_MODE_DEFAULT, disable_oob=False, stmtcachesize=oracledb.defaults.stmtcachesize, \
@@ -324,6 +335,17 @@ Oracledb Methods
324335
is not needed for cwallet.sso files that are used in the python-oracledb Thick
325336
mode.
326337

338+
The ``access_token`` parameter is expected to be a string or a 2-tuple or
339+
a callable. If it is a string, it specifies an Azure AD OAuth2 token used
340+
for Open Authorization (OAuth 2.0) token based authentication. If it is a
341+
2-tuple, it specifies the token and private key strings used for Oracle
342+
Cloud Infrastructure (OCI) Identity and Access Management (IAM) token based
343+
authentication. If it is a callable, it returns either a string or a 2-tuple
344+
used for OAuth 2.0 or OCI IAM token based authentication and is useful when
345+
the pool needs to expand and create new connections but the current
346+
authentication token has expired. This value is used in both the
347+
python-oracledb Thin and Thick modes.
348+
327349
The ``host`` parameter is expected to be a string which specifies the name or IP
328350
address of the machine hosting the listener, which handles the initial
329351
connection to the database. This value is used in both the python-oracledb
@@ -489,16 +511,15 @@ Oracledb Methods
489511
wait_timeout=0, max_lifetime_session=0, session_callback=None, \
490512
max_sessions_per_shard=0, soda_metadata_cache=False, ping_interval=60, \
491513
user=None, proxy_user=None, password=None, newpassword=None, \
492-
wallet_password=None, host=None, port=1521, protocol="tcp", \
493-
https_proxy=None, https_proxy_port=0, service_name=None, sid=None, \
494-
server_type=None, cclass=None, purity=oracledb.PURITY_DEFAULT, \
514+
wallet_password=None, access_token=None, host=None, port=1521, \
515+
protocol="tcp", https_proxy=None, https_proxy_port=0, service_name=None, \
516+
sid=None, server_type=None, cclass=None, purity=oracledb.PURITY_DEFAULT, \
495517
expire_time=0, retry_count=0, retry_delay=0, tcp_connect_timeout=60.0, \
496-
ssl_server_dn_match=True, ssl_server_cert_dn=None, \
497-
wallet_location=None, events=False, externalauth=False, \
498-
mode=oracledb.AUTH_MODE_DEFAULT, disable_oob=False, \
499-
stmtcachesize=oracledb.defaults.stmtcachesize, edition=None, tag=None, \
500-
matchanytag=False, config_dir=oracledb.defaults.config_dir, appcontext=[], \
501-
shardingkey=[], supershardingkey=[], debug_jdwp=None, handle=0)
518+
ssl_server_dn_match=True, ssl_server_cert_dn=None, wallet_location=None, \
519+
events=False, externalauth=False, mode=oracledb.AUTH_MODE_DEFAULT, \
520+
disable_oob=False, stmtcachesize=oracledb.defaults.stmtcachesize, edition=None, \
521+
tag=None, matchanytag=False, config_dir=oracledb.defaults.config_dir, \
522+
appcontext=[], shardingkey=[], supershardingkey=[], debug_jdwp=None, handle=0)
502523

503524
Creates a connection pool with the supplied parameters and returns the
504525
:ref:`ConnectionPool object <connpool>` for the pool. See :ref:`Connection
@@ -619,6 +640,17 @@ Oracledb Methods
619640
``wallet_password`` parameter is not needed for cwallet.sso files that are
620641
used in the python-oracledb Thick mode.
621642

643+
The ``access_token`` parameter is expected to be a string or a 2-tuple or
644+
a callable. If it is a string, it specifies an Azure AD OAuth2 token used
645+
for Open Authorization (OAuth 2.0) token based authentication. If it is a
646+
2-tuple, it specifies the token and private key strings used for Oracle
647+
Cloud Infrastructure (OCI) Identity and Access Management (IAM) token based
648+
authentication. If it is a callable, it returns either a string or a 2-tuple
649+
used for OAuth 2.0 or OCI IAM token based authentication and is useful when
650+
the pool needs to expand and create new connections but the current
651+
authentication token has expired. This value is used in both the
652+
python-oracledb Thin and Thick modes.
653+
622654
The ``host`` parameter is expected to be a string which specifies the name
623655
or IP address of the machine hosting the listener, which handles the
624656
initial connection to the database. This value is used in both the
@@ -894,15 +926,15 @@ Oracledb Methods
894926
wait_timeout=0, max_lifetime_session=0, session_callback=None, \
895927
max_sessions_per_shard=0, soda_metadata_cache=False, ping_interval=60, \
896928
user=None, proxy_user=Nonde, password=None, newpassword=None, \
897-
wallet_password=None, host=None, port=1521, protocol="tcp", \
929+
wallet_password=None, access_token=None, host=None, port=1521, protocol="tcp", \
898930
https_proxy=None, https_proxy_port=0, service_name=None, sid=None, \
899931
server_type=None, cclass=None, purity=oracledb.PURITY_DEFAULT, \
900932
expire_time=0, retry_count=0, retry_delay=0, tcp_connect_timeout=60.0, \
901933
ssl_server_dn_match=True, ssl_server_cert_dn=None, wallet_location=None, \
902-
events=False, externalauth=False, mode=oracledb.AUTH_MODE_DEFAULT, disable_oob=False, \
903-
stmtcachesize=oracledb.defaults.stmtcachesize, edition=None, tag=None, \
904-
matchanytag=False, config_dir=oracledb.defaults.config_dir, appcontext=[], \
905-
shardingkey=[], supershardingkey=[], debug_jdwp=None, handle=0)
934+
events=False, externalauth=False, mode=oracledb.AUTH_MODE_DEFAULT, \
935+
disable_oob=False, stmtcachesize=oracledb.defaults.stmtcachesize, edition=None, \
936+
tag=None, matchanytag=False, config_dir=oracledb.defaults.config_dir, \
937+
appcontext=[], shardingkey=[], supershardingkey=[], debug_jdwp=None, handle=0)
906938

907939
Creates and returns a :ref:`PoolParams Object <poolparam>`. The object
908940
can be passed to :meth:`oracledb.create_pool()`.
@@ -993,6 +1025,17 @@ Oracledb Methods
9931025
``wallet_password`` parameter is not needed for cwallet.sso files that are
9941026
used in the python-oracledb Thick mode.
9951027

1028+
The ``access_token`` parameter is expected to be a string or a 2-tuple or
1029+
a callable. If it is a string, it specifies an Azure AD OAuth2 token used
1030+
for Open Authorization (OAuth 2.0) token based authentication. If it is a
1031+
2-tuple, it specifies the token and private key strings used for Oracle
1032+
Cloud Infrastructure (OCI) Identity and Access Management (IAM) token based
1033+
authentication. If it is a callable, it returns either a string or a 2-tuple
1034+
used for OAuth 2.0 or OCI IAM token based authentication and is useful when
1035+
the pool needs to expand and create new connections but the current
1036+
authentication token has expired. This value is used in both the
1037+
python-oracledb Thin and Thick modes.
1038+
9961039
The ``host`` parameter is expected to be a string which specifies the name
9971040
or IP address of the machine hosting the listener, which handles the
9981041
initial connection to the database. This value is used in both the

doc/src/api_manual/pool_params.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ PoolParams Methods
3535
.. method:: PoolParams.set(min=None, max=None, increment=None, connectiontype=None, \
3636
getmode=None, homogeneous=None, timeout=None, wait_timeout=None, \
3737
max_lifetime_session=None, session_callback=None, max_sessions_per_shard=None, \
38-
soda_metadata_cache=None, ping_interval=None, user=None, proxy_user=None, password=None, \
39-
newpassword=None, wallet_password=None, host=None, port=None, protocol=None, \
40-
https_proxy=None, https_proxy_port=None, service_name=None, sid=None, \
41-
server_type=None, cclass=None, purity=None, expire_time=None, retry_count=None, \
42-
retry_delay=None, tcp_connect_timeout=None, ssl_server_dn_match=None, \
43-
ssl_server_cert_dn=None, wallet_location=None, events=None, externalauth=None, \
44-
mode=None, disable_oob=None, stmtcachesize=None, edition=None, tag=None, \
45-
matchanytag=None, config_dir=None, appcontext=[], shardingkey=[], supershardingkey=[], \
46-
debug_jdwp=None, handle=None)
38+
soda_metadata_cache=None, ping_interval=None, user=None, proxy_user=None,\
39+
password=None, newpassword=None, wallet_password=None, access_token=None, \
40+
host=None, port=None, protocol=None, https_proxy=None, https_proxy_port=None, \
41+
service_name=None, sid=None, server_type=None, cclass=None, purity=None, \
42+
expire_time=None, retry_count=None, retry_delay=None, tcp_connect_timeout=None, \
43+
ssl_server_dn_match=None, ssl_server_cert_dn=None, wallet_location=None, \
44+
events=None, externalauth=None, mode=None, disable_oob=None, stmtcachesize=None, \
45+
edition=None, tag=None, matchanytag=None, config_dir=None, appcontext=[], \
46+
shardingkey=[], supershardingkey=[], debug_jdwp=None, handle=None)
4747

4848
Sets one or more of the parameters.
4949

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Thick Mode Changes
3838
Common Changes
3939
++++++++++++++
4040

41+
#) Added support for token authentication (Azure OAuth and IAM) via the new
42+
parameter `access_token` to :func:`oracledb.connect()` and
43+
:func:`oracledb.create_pool()`.
4144
#) Added method :func:`oracledb.is_thin_mode()` to support determining whether
4245
the driver is using thin mode or not
4346
(`issue 16 <https://github.com/oracle/python-oracledb/issues/10>`__).

doc/src/user_guide/appendix_a.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,13 @@ see :ref:`driverdiff` and :ref:`compatibility`.
7474
- No
7575
- Yes
7676
- Yes
77-
* - Oracle Cloud Infrastructure Identity and Access Management (IAM) Tokens
78-
- No
77+
* - Oracle Cloud Infrastructure (OCI) Identity and Access Management (IAM) Tokens (see :ref:`iamauth`)
78+
- Yes
79+
- Yes
7980
- Yes - in connection string with appropriate Oracle Client
81+
* - Open Authorization (OAuth 2.0) (see :ref:`oauth2`)
82+
- Yes
83+
- Yes
8084
- Yes - in connection string with appropriate Oracle Client
8185
* - Kerberos and Radius authentication
8286
- No

doc/src/user_guide/appendix_b.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,22 @@ bare name as a hostname is important to you in the python-oracledb Thin mode,
177177
then you can alter the connection string to include a port number such as
178178
``hostname:1521`` or a protocol such as ``tcp://hostname``.
179179

180+
Token Based Authentication
181+
--------------------------
182+
183+
In the python-oracledb Thin mode:
184+
185+
- When connecting to Oracle Cloud Database with mutual TLS (mTLS) using OAuth2
186+
tokens, you need to explicitly set the ``config_dir``, ``wallet_location``,
187+
and ``wallet_password`` parameters of :func:`~oracledb.connect` or
188+
:func:`~oracledb.create_pool()`. See, :ref:`autonomousdb`.
189+
190+
- :ref:`Open Authorization (OAuth 2.0) token based authentication connection
191+
strings <oauth2connstr>` and :ref:`Oracle Cloud Infrastructure (OCI) Identity
192+
and Access Management (IAM) token based authentication connection strings
193+
<iamauthconnstr>` are not supported. Use ``access_token`` parameter of
194+
:func:`oracledb.ConnectParams()` instead. See :ref:`tokenauth`.
195+
180196
Transport Layer Security (TLS) Support
181197
--------------------------------------
182198

0 commit comments

Comments
 (0)