node.jsoracle-databasenode-oracledboracle-wallet

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:\code\js\myoracledb-app\wallet)

)

)

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.


Solution

  • I adjusted the sqlnet.ora as follows:

    WALLET_LOCATION=
    
    (SOURCE=
    
    (METHOD=FILE)
    
    (METHOD_DATA=
    
    (DIRECTORY=D:\code\js\myoracledb-app\wallet)
    
    )
    
    )
    
    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)