Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
517 views
in Technique[技术] by (71.8m points)

node.js - nodejs oracledb externalAuth (using oracle wallet)

In this sample nodejs app I am trying to connect to oracle database with a wallet. The wallet is created in the server, and, the contents of the wallet directory was zipped and unzipped into my project's root folder (inside a folder called wallet).

Further included sqlnet.ora file in the same folder. Its contents are:

WALLET_LOCATION=

(SOURCE=

(METHOD=FILE)

(METHOD_DATA=

(DIRECTORY=D:codejsmyoracledb-appwallet)

)

)

The main program (index.js) is pretty straight forward:

const oracledb = require('oracledb');
const path = require('path');
const configDir = path.join(__dirname, 'wallet');
// oracledb.initOracleClient({ configDir: configPath });
// oracledb.initOracleClient();
const poolOptions = {  
  externalAuth: true,
  connectionString: '8.83.87.12:1522/ORCLCDB',
  configDir  
};

oracledb.createPool(poolOptions, function(err, pool){
  if(err) {
    console.error(err);
    process.exit(1);
  }
  else {
    pool.getConnection(function(err, conn){
      if(err) {
        console.error(err);
        process.exit(2);
      }
      else {
        conn.execute('select sysdate from dual', [], {}, function(err, result){
          if(err) {
            console.error(err);
            process.exit(3);
          }
          else {
            
            conn.release(function(){
              console.log('Result:', JSON.stringify(result));
              process.exit(0);
            });
          }
        });
      }
    });
  }
});

I have used oracledb as the client to connect to my remote database. I get an error in the callback for pool.getConnection(). This is verified by the error code returned.

The error output to console is:

[Error: ORA-01017: invalid username/password; logon denied] {
  errorNum: 1017,
  offset: 0
}

I have tried various of trying to initialize the oracledb client (oracledb.initOraClient()), but, the result is the same. What am I doing wrong here?

Ps: if interested in how the wallet was created read this post and its comments.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I adjusted the sqlnet.ora as follows:

WALLET_LOCATION=

(SOURCE=

(METHOD=FILE)

(METHOD_DATA=

(DIRECTORY=D:codejsmyoracledb-appwallet)

)

)

SQLNET.WALLET_OVERRIDE=TRUE

Next, the pool options were defined as follows:

const poolOptions = {  
  externalAuth: true,
  connectionString: 'ORCLCDB'
};

The ORCLCDB service name was defined in the tnsnames.ora.

ORCLCDB =
  (DESCRIPTION =
    (ADDRESS_LIST =
     (ADDRESS = (PROTOCOL = TCP)(HOST = <host_ip_or_name>)(PORT = <server_port>))
    )
    (CONNECT_DATA =
     (SERVICE_NAME =ORCLCDB)
    )    
   )

Both sqlnet.ora and tnsnames.ora file was placed in the wallet folder. Set TNS_ADMIN environment variable to the wallet folder. Here is an example of how to do that in powershell:

PS1 > $env:TNS_ADMIN=$(join-path $pwd wallet)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...