tediousjs / tedious

Node TDS module for connecting to SQL Server databases.

Home Page:http://tediousjs.github.io/tedious/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[QUESTION] `azure-active-directory-default` Auto Token Refresh?

elliot-huffman opened this issue · comments

Question
Does Tedious.Js automatically get a new access token when using any of the pre-built @Azure/Identity integrated auth options?

E.g. Access token is short lived, say 1 hour, when this expires, will Tedious get a new token automatically when the current one expires?

No, we don't support auto-refresh, and I'm not sure tedious is the correct place to put the auto-refresh logic into. I think it should be handled by consumers of tedious (probably another reason to deprecate the existing azure identity options and just replace them with what you proposed in the token credential PR).

Maybe I don't understand, but when connecting via token authentication to SQL server, the token is only required when the connection is established. Once the connection is established, the token won't be used at any later point in time on that connection.

tedious does not support re-connecting the same connection again, there's too much internal state that's not cleaned up properly to cleanly allow re-connecting. The current way to handle connection errors is to throw away the connection and create a new connection instead.

I believe your PR already solves the "getToken is expensive" issue. azure/identity caches the getToken response per credential object, so if you re-use the same credential object across different connections, we will end up re-using the already previously requested token. Note that this does not work in the current azure-* authentication methods, because those create a new credential object on each connection attempt.

I believe your PR already solves the "getToken is expensive" issue. azure/identity caches the getToken response per credential object, so if you re-use the same credential object across different connections, we will end up re-using the already previously requested token. Note that this does not work in the current azure-* authentication methods, because those create a new credential object on each connection attempt.

At least this is based on my understanding of how @azure/identity is supposed to have an in-memory cache.