[Fixed] Angular 16 and MSAL 3.0: BrowserAuthError: native_broker_called_before_initialize – Angular

by
Ali Hasan
angular azure-ad-msal msal-angular react-typescript

The Problem:

You are developing an Angular 16 single-page application and attempting to integrate MSAL 3.0 (beta). Upon adding MSAL, you encounter a "BrowserAuthError: native_broker_called_before_initialize" error. You’re seeking assistance to resolve this issue and obtain a complete example of using MSAL with Angular Standalone Components and pop-up login.

The Solutions:

Solution 1: Disable Native Broker

The error "native_broker_called_before_initialize" occurs when the MSAL native broker is called before it’s initialized. To fix this, you need to disable the native broker in your MSAL configuration:

provide: MSAL_INSTANCE,
useValue: new PublicClientApplication({
    auth: {
        ...
    },
    cache: {
        ...
    },
    system: {
        allowNativeBroker: false, // Disables WAM Broker
    }
})

Q&A

MSAL native broker was called before initialize()

Disable the native broker in your MSAL config when creating the MSAL instance.

How to allow native broker?

Allow native broker in your MSAL config when creating the MSAL instance.

What does allowNativeBroker do in MSAL?

allowNativeBroker disallows or allows the use of the native broker.

Video Explanation:

The following video, titled "Deep dive on using MSAL.js to integrate Angular single-page ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

This month's in-depth topic: Deep dive on using MSAL.js to integrate Angular single-page applications with Azure Active Directory.