I am trying to connect to SQL Server via ActiveDirectoryPassword authentication mechanism and I am using 'Tedious' for that.
However whenever I run my project I run into the:
Security token could not be authenticated or authorized
Below is my code sample which I derived after referring to PAGE ON STACKOVERFLOW and Microsoft official page guide.
var Connection = require('tedious').Connection;
const config = {
server: 'server-name.database.windows.net',
options: {
database: 'database-name',
encrypt: true,
port: 1433
},
authentication: {
type: "azure-active-directory-password",
options: {
userName: "myusername",
password: "mypassword",
}
}
}
var connection = new Connection(config);
connection.on("connect", err => {
if (err) {
console.error(err.message);
} else {
console.log("Connected");
}
});
connection.connect();
What can be the possible reason for this error? Thanks.