|
1 |
| -// Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved |
| 1 | +// Copyright (c) 2015, 2022, Oracle and/or its affiliates. |
2 | 2 |
|
3 | 3 | //-----------------------------------------------------------------------------
|
4 | 4 | //
|
@@ -105,6 +105,7 @@ class OracleDb {
|
105 | 105 | this.createPool = nodbUtil.callbackify(createPool).bind(_oracledb);
|
106 | 106 | this.shutdown = nodbUtil.callbackify(shutdown).bind(_oracledb);
|
107 | 107 | this.startup = nodbUtil.callbackify(startup).bind(_oracledb);
|
| 108 | + this.initOracleClient = this.initOracleClient.bind(_oracledb); |
108 | 109 | }
|
109 | 110 |
|
110 | 111 | // temporary method for determining if an object is a date until
|
@@ -198,6 +199,39 @@ async function createPool(poolAttrs) {
|
198 | 199 | tempUsedPoolAliases[poolAlias] = true;
|
199 | 200 | }
|
200 | 201 |
|
| 202 | + if (adjustedPoolAttrs.accessToken !== undefined) { |
| 203 | + // token and privateKey must be set for token based |
| 204 | + // authentication |
| 205 | + if (adjustedPoolAttrs.accessToken.token === undefined || |
| 206 | + adjustedPoolAttrs.accessToken.token === '' || |
| 207 | + adjustedPoolAttrs.accessToken.privateKey === undefined || |
| 208 | + adjustedPoolAttrs.accessToken.privateKey === '') { |
| 209 | + throw new Error(nodbUtil.getErrorMessage('NJS-084')); |
| 210 | + } |
| 211 | + |
| 212 | + // cannot set username or password for token based authentication |
| 213 | + if (adjustedPoolAttrs.user !== undefined || |
| 214 | + adjustedPoolAttrs.password !== undefined) { |
| 215 | + throw new Error(nodbUtil.getErrorMessage('NJS-084')); |
| 216 | + } |
| 217 | + |
| 218 | + // homogeneous and externalAuth must be set to true for token based |
| 219 | + // authentication |
| 220 | + if (adjustedPoolAttrs.homogeneous === false || |
| 221 | + adjustedPoolAttrs.externalAuth === false) { |
| 222 | + throw new Error(nodbUtil.getErrorMessage('NJS-085')); |
| 223 | + } |
| 224 | + |
| 225 | + adjustedPoolAttrs.token = adjustedPoolAttrs.accessToken.token; |
| 226 | + adjustedPoolAttrs.privateKey = |
| 227 | + adjustedPoolAttrs.accessToken.privateKey; |
| 228 | + } |
| 229 | + |
| 230 | + if (adjustedPoolAttrs.accessToken === undefined && |
| 231 | + adjustedPoolAttrs.accessTokenCallback !== undefined) { |
| 232 | + throw new Error(nodbUtil.getErrorMessage('NJS-084')); |
| 233 | + } |
| 234 | + |
201 | 235 | try {
|
202 | 236 | const pool = await this._createPool(adjustedPoolAttrs);
|
203 | 237 |
|
@@ -270,6 +304,32 @@ async function getConnection(a1) {
|
270 | 304 |
|
271 | 305 | // otherwise, create a new standalone connection
|
272 | 306 | } else {
|
| 307 | + if (connAttrs.accessToken !== undefined) { |
| 308 | + // token and privateKey must be set for token based |
| 309 | + // authentication |
| 310 | + if (connAttrs.accessToken.token === undefined || |
| 311 | + connAttrs.accessToken.token === '' || |
| 312 | + connAttrs.accessToken.privateKey === undefined || |
| 313 | + connAttrs.accessToken.privateKey === '') { |
| 314 | + throw new Error(nodbUtil.getErrorMessage('NJS-084')); |
| 315 | + } |
| 316 | + |
| 317 | + // cannot set username or password for token based authentication |
| 318 | + if (connAttrs.user !== undefined || |
| 319 | + connAttrs.password !== undefined) { |
| 320 | + throw new Error(nodbUtil.getErrorMessage('NJS-084')); |
| 321 | + } |
| 322 | + |
| 323 | + // externalAuth must be set to true for token based authentication |
| 324 | + if (connAttrs.externalAuth === false) { |
| 325 | + throw new Error(nodbUtil.getErrorMessage('NJS-086')); |
| 326 | + } |
| 327 | + |
| 328 | + connAttrs.token = connAttrs.accessToken.token; |
| 329 | + connAttrs.privateKey = |
| 330 | + connAttrs.accessToken.privateKey; |
| 331 | + } |
| 332 | + |
273 | 333 | try {
|
274 | 334 | return await this._getConnection(connAttrs);
|
275 | 335 | } catch (err) {
|
|
0 commit comments