Search code examples
node.jsoracle-databaseexpressnode-oracledbpassport-azure-ad

Connect to database oracle using token msal


I am developing a backend in node with express, passport-azure-ad and oracledb, using this library to connect to Oracle, in the front end I use angular with the msal library to authenticate and obtain a token, is there any way to connect to a Oracle XE/Enteprise database with this same token?

I need to maintain data traceability with registered users


Solution

  • You can't use that token to authenticate. However once you have connected, you can set one or more of the 'end-to-end' tracing attributes shown in the node-oracledb doc End-to-end Tracing, Mid-tier Authentication, and Auditing to maintain data traceability, for example:

    const connection = await oracledb.getConnection(
      {
        user          : "mygenericuser",
        password      : mypw,
        connectString : "localhost/orclpdb1"
      }
    );
    
    connection.clientId = "myactualname";  // This gets recorded in audit trails etc
    

    The old article PHP Web Auditing, Authorization and Monitoring with Oracle Database may also be useful background.