Skip to content

Commit a6fbc39

Browse files
authored
[Identity] InteractiveBrowserCredential for Node now waits for the listener to start listening (Azure#15497)
* [Identity] Attempting to fix odd bug on Windows tests * listening before allowing any throw * one less change * just throwing the error we receive
1 parent cc05f39 commit a6fbc39

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

sdk/identity/identity/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 2.0.0-beta.4 (Unreleased)
44

5+
## Bug fixes
6+
7+
- Fixed an issue in which `InteractiveBrowserCredential` on Node would sometimes cause the process to hang if there was no browser available.
58
### Breaking changes
69

710
- Removed the protected method `getAzureCliAccessToken` from the public API of the `AzureCliCredential`. While it will continue to be available as part of v1, we won't be supporting this method as part of v2's public API.

sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,13 @@ export class MsalOpenBrowser extends MsalNode {
138138
cleanup();
139139
});
140140
};
141+
141142
const app = http.createServer(requestListener);
143+
const server = stoppable(app);
142144

143145
const listen = app.listen(this.port, this.hostname, () =>
144146
this.logger.info(`InteractiveBrowserCredential listening on port ${this.port}!`)
145147
);
146-
app.on("connection", (socket) => socketToDestroy.push(socket));
147-
const server = stoppable(app);
148-
149-
this.openAuthCodeUrl(scopes).catch((e) => {
150-
cleanup();
151-
reject(e);
152-
});
153148

154149
function cleanup(): void {
155150
if (listen) {
@@ -166,13 +161,24 @@ export class MsalOpenBrowser extends MsalNode {
166161
}
167162
}
168163

169-
const abortSignal = options?.abortSignal;
170-
if (abortSignal) {
171-
abortSignal.addEventListener("abort", () => {
164+
app.on("connection", (socket) => socketToDestroy.push(socket));
165+
166+
app.on("listening", () => {
167+
const openPromise = this.openAuthCodeUrl(scopes);
168+
169+
const abortSignal = options?.abortSignal;
170+
if (abortSignal) {
171+
abortSignal.addEventListener("abort", () => {
172+
cleanup();
173+
reject(new Error("Aborted"));
174+
});
175+
}
176+
177+
openPromise.then().catch((e) => {
172178
cleanup();
173-
reject(new Error("Aborted"));
179+
reject(e);
174180
});
175-
}
181+
});
176182
});
177183
}
178184

0 commit comments

Comments
 (0)