Connecting Sequelize to MSSQL with Windows Authentication

3k Views Asked by At

I need help with the right libraries to connect Sequelize to MSSQL database using Windows Authentication.

I have a requirement for a client where I cannot use passwords to connect to the database on the server. Their required method of use is to connect to MSSQL database using Windows Authentication.

The problem I have is that we are using Sequelize and the only Dialect using msnodesqlv8 (which supports Windows Authentication) that I was able to find is not maintained any more. https://www.npmjs.com/package/sequelize-msnodesqlv8

Tedious which is the default dialect for Sequelize does not support Windows Authentication without password. It has the option of using ntlm, but it also requires a password.

2

There are 2 best solutions below

0
On BEST ANSWER

Update: https://www.npmjs.com/package/msnodesqlv8 supports windows authentication. There are some slight changes in the way they handle some data types like BigInt. Other than that, it works pretty well.

Though, I had already created a custom version of tedious driver with sspi-client https://www.npmjs.com/package/@sregger/sspi-client thanks to some legacy code samples and help from Tediousjs community. So I kept it. One word of caution is that if you are using sspi-client, Worker will not work. To use Worker, use custom library https://www.npmjs.com/package/shinobi-worker otherwise you will get the error of "Module did not self-register"

0
On

I found the solution with this configuration:

database: 'DB_NAME',
  host: 'DB_HOST',
  dialect: 'mssql',
  dialectOptions: {
    authentication: {
      type: 'ntlm',
      options: {
      userName: 'DB_USER',
      password: 'DB_PASS',
      domain: 'MY_COMPANY_DOMAIN',
    },
  },
  options: {
    port: 1433,
    requestTimeout: 60000,
  },
},

moreinfo: https://github.com/vishwasjois/sequelize/blob/988e754c6eef323b1a9dc11f5bee3fb535579da8/docs/upgrade-to-v5.md#dialect-specific

Hope this help