Skip to content

Commit 9a2fd32

Browse files
authored
[EventHub] Fix a regression in token renewal (Azure#26297)
In our previous refactoring, we accidentally dropped the `getToken()` calls when renewing token. This PR adds the calls back. The internal `TokenInfo` property `timeoutInMs` is renamed to `timeToLiveInMs` to avoid confusion with operation timeout parameter `timeoutInMs`.
1 parent fe58190 commit 9a2fd32

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

sdk/eventhub/event-hubs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Bugs Fixed
1010

11+
- Fix a regression of missing `getToken` calls when renewing tokens.
12+
1113
### Other Changes
1214

1315
## 5.11.0 (2023-06-08)

sdk/eventhub/event-hubs/src/withAuth.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@ export async function withAuth(
4141
await callback();
4242
async function createTask() {
4343
try {
44-
await setupClaimNegotiation(context, audience, info, timeoutInMs, logger, options);
44+
const info2 = await getTokenInfo(context.tokenCredential, audience);
45+
await setupClaimNegotiation(context, audience, info2, timeoutInMs, logger, options);
4546
logger.verbose(
46-
`next token renewal is in ${info.timeoutInMs} milliseconds @(${new Date(
47-
Date.now() + info.timeoutInMs
47+
`next token renewal is in ${info2.timeToLiveInMs} milliseconds @(${new Date(
48+
Date.now() + info2.timeToLiveInMs
4849
).toString()}).`
4950
);
5051
} catch (err) {
5152
logger.verbose(`an error occurred while renewing the token: ${logObj(err)}`);
5253
}
5354
}
54-
const loop = createTimerLoop(info.timeoutInMs, createTask);
55+
const loop = createTimerLoop(info.timeToLiveInMs, createTask);
5556
loop.start();
5657
return loop;
5758
}
@@ -88,7 +89,7 @@ interface TokenInfo {
8889
/** The type of the token */
8990
type: TokenType;
9091
/** The time duration after which the token should be refreshed */
91-
timeoutInMs: number;
92+
timeToLiveInMs: number;
9293
}
9394

9495
async function getAadToken(cred: TokenCredential): Promise<TokenInfo> {
@@ -99,15 +100,15 @@ async function getAadToken(cred: TokenCredential): Promise<TokenInfo> {
99100
return {
100101
token,
101102
type: TokenType.CbsTokenTypeJwt,
102-
timeoutInMs: token.expiresOnTimestamp - Date.now() - 2 * 60 * 1000,
103+
timeToLiveInMs: token.expiresOnTimestamp - Date.now() - 2 * 60 * 1000,
103104
};
104105
}
105106

106107
function getSharedKeyBasedToken(cred: SasTokenProvider, audience: string): TokenInfo {
107108
return {
108109
token: cred.getToken(audience),
109110
type: TokenType.CbsTokenTypeSas,
110-
timeoutInMs: 45 * 60 * 1000,
111+
timeToLiveInMs: 45 * 60 * 1000,
111112
};
112113
}
113114

0 commit comments

Comments
 (0)