Skip to content

Commit

Permalink
Add additional logging for NAA initialization (#7064)
Browse files Browse the repository at this point in the history
Add additional logging for NAA initialization to help diagnose if
NestAppAuthController is being used for the session, or if it is falling
back to StandardController. Also log exception that occurred in trying
to use Nested App Auth bridge to get further details on failure cases.
The change also avoids the time spent trying to initialize the bridge if
caller does not opt-in to supportsNestedAppAuth.
  • Loading branch information
codexeon authored Apr 30, 2024
1 parent 23280a4 commit 9d7cdec
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Add additional logging for Nested App Auth initialization errors (#7064)",
"packageName": "@azure/msal-browser",
"email": "[email protected]",
"dependentChangeType": "patch"
}
5 changes: 1 addition & 4 deletions lib/msal-browser/src/controllers/ControllerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ export async function createController(

await Promise.all(operatingContexts);

if (
teamsApp.isAvailable() &&
teamsApp.getConfig().auth.supportsNestedAppAuth
) {
if (teamsApp.isAvailable()) {
const controller = await import("./NestedAppAuthController");
return controller.NestedAppAuthController.createController(teamsApp);
} else if (standard.isAvailable()) {
Expand Down
22 changes: 14 additions & 8 deletions lib/msal-browser/src/operatingcontext/TeamsAppOperatingContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export class TeamsAppOperatingContext extends BaseOperatingContext {
* TODO: Add implementation to check for presence of inject Nested App Auth Bridge JavaScript interface
*
*/

if (!this.getConfig().auth.supportsNestedAppAuth) {
return false;
}

try {
if (typeof window !== "undefined") {
const bridgeProxy: IBridgeProxy = await BridgeProxy.create();
Expand All @@ -74,18 +79,19 @@ export class TeamsAppOperatingContext extends BaseOperatingContext {
this.activeAccount =
await bridgeProxy.getActiveAccount();
}
} catch (e) {
this.activeAccount = undefined;
} catch {
// Ignore errors
}
this.bridgeProxy = bridgeProxy;
this.available = bridgeProxy !== undefined;
} else {
this.available = false;
}
} catch (e) {
this.available = false;
} finally {
return this.available;
} catch (ex) {
this.logger.infoPii(
`Could not initialize Nested App Auth bridge (${ex})`
);
}

this.logger.info(`Nested App Auth Bridge available: ${this.available}`);
return this.available;
}
}

0 comments on commit 9d7cdec

Please sign in to comment.