-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Description
Feature Description
Hi,
I am using managed identities from Azure for authenticating to Sql server database.
I am creating a datasource:
new DataSource({
type: 'mssql',
host: ...
port: ...
authentication: {
type: "azure-active-directory-access-token",
options: {
token: await secretsService.getDbAuthToken(),
},
},
the datasource it is created at the start of the application, however the token from Azure expires after 24 hours, and I need a way to refresh,
I have tried to use the setOptions method from the Datasource but it doesn' t have any effect on the token already set on the connection pool.
The only way I could refresh the token is by getting the connection pool and refreshing it periodically
setInterval(async() => {
const connectionPool= await dataSource.driver.obtainMasterConnection()
connectionPool.config.authentication.options.token=
The Solution
is it possible to offer a way to refresh the token at a specific interval, maybe token can be a callback?
for example some tedius implemented that tediousjs/tedious#1144
mssql has that
const sql = require('mssql');
const { PublicClientApplication } = require('@azure/msal-node');
const config = {
server: 'teststeliana.database.windows.net',
database: 'teststeliana',
authentication: {
type: 'azure-active-directory-default',
options: {
tokenProvider: async () => {
const pca = new PublicClientApplication({
auth: {
},
});
const tokenRequest = {
scopes: ['https://database.windows.net/.default'],
};
const response = await pca.acquireTokenByDeviceCode(tokenRequest);
return response.accessToken;
},
},
},
options: {
encrypt: true,
},
};
Considered Alternatives
Currently I am using something like this:
setInterval(async() => {
const connectionPool= await dataSource.driver.obtainMasterConnection()
connectionPool.config.authentication.options.token=
And I manipulate the connection pool configuration directly
Additional Context
No response
Relevant Database Driver(s)
- aurora-mysql
- aurora-postgres
- better-sqlite3
- cockroachdb
- cordova
- expo
- mongodb
- mysql
- nativescript
- oracle
- postgres
- react-native
- sap
- spanner
- sqlite
- sqlite-abstract
- sqljs
- sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
Yes, I have the time, and I know how to start.