MSAL (Microsoft Authentication Library) provider implementation - v3.0.0

Implements the abstract methods from MJAuthBase to hide MSAL-specific details. The key abstraction is that MSAL stores the JWT in AuthenticationResult.idToken, but consumers never need to know this detail.

Hierarchy (view full)

Implements

  • OnDestroy

Constructors

Properties

_destroying$: Subject<void> = ...
_initPromise: null | Promise<void> = null
_initializationCompleted$: BehaviorSubject<boolean> = ...
auth: MsalService
isAuthenticated$: BehaviorSubject<boolean> = ...
msalBroadcastService: MsalBroadcastService
type: "msal" = MJMSALProvider.PROVIDER_TYPE

Provider type identifier Must be implemented by concrete providers

userEmail$: BehaviorSubject<string> = ...
userInfo$: BehaviorSubject<null | StandardUserInfo> = ...
PROVIDER_TYPE: "msal" = 'msal'

Accessors

Methods

  • Get profile picture URL from auth provider

    Returns the user's profile picture URL if available from the auth provider. This abstracts away provider-specific logic:

    • Microsoft/MSAL: Fetches from Graph API
    • Auth0/Okta: Returns from user claims

    Returns Promise<null | string>

    Promise resolving to image URL or null if not available

    Example

    const pictureUrl = await this.authBase.getProfilePictureUrl();
    if (pictureUrl) {
    this.userAvatar = pictureUrl;
    }
  • Refresh authentication token

    Attempts to obtain a fresh authentication token using the provider's refresh mechanism. If silent refresh fails due to session expiry, the provider will handle re-authentication automatically (which may involve redirecting to the auth provider's login page).

    Returns StandardAuthToken on success, or throws on complete failure.

    IMPORTANT: If the provider requires interactive re-authentication (redirect or popup), this method may never return. The app will reload after authentication completes and re-initialize with a fresh token.

    Returns Promise<StandardAuthToken>

    Promise resolving to StandardAuthToken or throws on failure

    Example

    const token = await this.authBase.refreshToken();
    return token.idToken; // Always succeeds or throws
  • Factory function to provide Angular dependencies required by MSAL Stored as a static property for the factory to access without instantiation

    Parameters

    • environment: Record<string, unknown>

    Returns (typeof MsalService | typeof MsalBroadcastService | typeof MsalGuard | {
        provide: InjectionToken<string>;
        useValue: PublicClientApplication;
    } | {
        provide: InjectionToken<string>;
        useValue: {
            authRequest: {
                scopes: string[];
            };
            interactionType: InteractionType;
            protectedResourceMap?: undefined;
        };
    } | {
        provide: InjectionToken<string>;
        useValue: {
            authRequest?: undefined;
            interactionType: InteractionType;
            protectedResourceMap: Map<string, string[]>;
        };
    })[]