Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect() with a new Azure SQL Auth Token doesnt update the connection, causing Token Expired error #1122

Closed
cameronstubber opened this issue Oct 20, 2020 · 5 comments

Comments

@cameronstubber
Copy link

I provide an authenticated Azure AD Token in the Connection Options, which is good for 60 minutes, to the Connect() function. I track the token value over time, and once it has been refreshed, I call Connect() with a new Connection Options containing the new token. The token does not get updated within node-mssql/tedious, and eventually the SQL Connection stops working and returns token-expired errors.

I'm sure this is probably just a lack of understanding on how to use the module to manage the connection pool with regards to Azure Tokens. Any help would be awesome.

The AzureLogin class is my own, it just tracks the TTL of the current token and asks for a new one and saves it if required.

Expected behaviour:

I expected that calling connect with a new token, would update the token value within the Connection Pool / Manager.

Actual behaviour:

The token value does not change, and I get a Token Expired error.

expiredazure

Configuration:

var dbConfig = {
    authentication: {
        type: 'azure-active-directory-access-token',
        options: {
            token: azureLogin.connect().accessToken
        }
    },
    server: serverAddress,
    database: databaseName,
    options: {
        trustServerCertificate: false,
        encrypt: true,
        port: 1433
    }
};

sql.connect(dbConfig).then(pool => {
    return pool.request()
        .query('SELECT * FROM TABLE');
}).then(result => {
    res.redirect('/');
}).catch(err => {
    console.error(err);
});

Software versions

  • NodeJS: 12
  • node-mssql: 6.2.3
  • tedious: 8.3.1
  • SQL Server: Azure SQL Service
@cameronstubber
Copy link
Author

Sorry, I should mention that I know my Azure Token is refreshed as I log the value of it.

@blaw2422
Copy link

blaw2422 commented Nov 4, 2020

can you show what kind of context this is being ran in? Does all of the code you posted run everytime you hit an endpoint?

@dhensby
Copy link
Collaborator

dhensby commented Nov 16, 2020

Are you closing the pool before you try to connect again? it won't use the new config when you call connect if the pool is already connected

@funkydev
Copy link
Contributor

@cameronstubber You need to establish a new connection after your app will receive a new token because tedious does not support injecting token generator. You could also try another authentication method, like using Service Principal Secret.

This more about tedious issue instead of mssql. You can find the related issue here: tediousjs/tedious#1144

@richard457
Copy link

@cameronstubber You need to establish a new connection after your app will receive a new token because tedious does not support injecting token generator. You could also try another authentication method, like using Service Principal Secret.

This more about tedious issue instead of mssql. You can find the related issue here: tediousjs/tedious#1144

A code sample is much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants