Error: Invalid tenant id provided while connecting node JS to AAD.

abhishek singh rana 1 Reputation point
2022-03-09T09:49:09.473+00:00

I am trying to connect my node js to SQL Server via ActiveDirectoryPassword authentication mechanism and I am using 'Tedious' for that.

Below is my code sample:

var Connection = require('tedious').Connection;  
const config = {      
    authentication: {          
        options: {  
            userName: 'myusername',  
            password: 'mypassword',  
            tenantId: '<3cbcd3-idsayXYZ0123456789-0d11484d>',  
        },  
        type: 'azure-active-directory-password',          
    },  
    server: 'server-name.database.windows.net',  
      
    options: {  
        database: 'database-name',  
        encrypt: true,  
        port: 1433  
    }      
};  
  
var connection = new Connection(config);    
    connection.on("connect", err => {  
        if (err) {                         
          console.error(err.message);  
        } else {  
            console.log("Connected");   
        }  
      });  
      
    connection.connect();  

However I ran into the error as:

(node:13300) DeprecationWarning: When using the azure-active-directory-password authentication method, please provide a value for the clientId option. This option will be required in a future release.
(Use node --trace-deprecation ... to show where the warning was created)
(node:13300) Warning: config.options.trustServerCertificate will default to false in the future. To silence this message, specify a value explicitly in the config options
C:\Node JS Projects\POC\node_modules@azure\identity\dist\index.js:550
throw error;
^

Error: Invalid tenant id provided. You can locate your tenant id by following the instructions listed here: https://learn.microsoft.com/partner-center/find-ids-and-domain-names.

I crossed checked the 'tenantId' multiple times with the 'Azure Active Directory' properties section of my organization on the azure portal. The 'tenantId' is matching as of azure portal. But still the error says 'Invalid tenant id provided'.

Azure SQL Database
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,561 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Siva-kumar-selvaraj 15,551 Reputation points
    2022-04-05T06:51:22.337+00:00

    Hi,

    Thanks for reaching out.

    As Pituach mentioned this need node js expertise. However, I would like to share genral guidance and some of sample related to Azure AD authentication with Azure SQL DB and DW. In case if you need MS support help, I will gladly open one-time free support for you if you have any active subscription. Hope this helps.

    https://techcommunity.microsoft.com/t5/azure-sql-blog/troubleshooting-problems-related-to-azure-ad-authentication-with/ba-p/1062991
    https://github.com/microsoft/sql-server-samples/tree/master/samples/features/security/azure-active-directory-auth
    https://stackoverflow.com/questions/46681021/can-not-connect-to-azure-sql-server-using-active-directory-integrated-authentica
    https://github.com/microsoft/sql-server-samples/tree/master/samples/features/security/azure-active-directory-auth/password

    0 comments No comments