Member Junction
    Preparing search index...

    Base class for Angular authentication providers - v3.0.0

    Provides common functionality and enforces the provider interface. All concrete providers (MSAL, Auth0, Okta) should extend this class.

    • Proper abstraction - no more leaky provider-specific logic
    • Standardized types - no more any types
    • Clean token access - no more __raw || idToken patterns
    • Semantic error handling - no more provider-specific error checks

    Extend this class and implement the abstract methods:

    • extractIdTokenInternal() - Extract token from provider storage
    • extractTokenInfoInternal() - Extract full token info
    • extractUserInfoInternal() - Map claims to StandardUserInfo
    • refreshTokenInternal() - Implement refresh mechanism
    • classifyErrorInternal() - Map errors to AuthErrorType

    3.0.0

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    isAuthenticated$: BehaviorSubject<boolean> = ...
    type: string

    Provider type identifier Must be implemented by concrete providers

    userEmail$: BehaviorSubject<string> = ...
    userInfo$: BehaviorSubject<StandardUserInfo | null> = ...

    Accessors

    Methods

    • Classify provider-specific error into standard error type

      Maps provider-specific errors to semantic AuthErrorType values. Examines error objects, error codes, and messages to determine the appropriate category (TOKEN_EXPIRED, INTERACTION_REQUIRED, NETWORK_ERROR, etc.).

      Parameters

      • error: unknown

        The error to classify

      Returns StandardAuthError

      StandardAuthError with categorized type and user-friendly message

    • Clears MJ client-side caches before logout.

      Removes all localStorage entries except those returned by preservedLocalStorageKeys, and deletes the MJ_Metadata IndexedDB database so a subsequent user session starts with a clean slate.

      Returns Promise<void>

    • Extract ID token from provider-specific storage

      This is where providers hide their implementation details.

      • Auth0: Extracts from claims.__raw
      • MSAL: Extracts from response.idToken
      • Okta: Extracts from authState.idToken

      Returns Promise<string | null>

      Promise resolving to token string or null if not authenticated

    • 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<string | null>

      Promise resolving to image URL or null if not available

      const pictureUrl = await this.authBase.getProfilePictureUrl();
      if (pictureUrl) {
      this.userAvatar = pictureUrl;
      }
    • Get profile picture URL from auth provider

      Retrieves the user's profile picture using provider-specific mechanisms. Some providers include the URL in user claims, others require API calls to fetch the image.

      Returns Promise<string | null>

      Promise resolving to image URL or null if not available

    • Handle session expiry when silent refresh fails

      Called internally when silent token refresh fails with TOKEN_EXPIRED or INTERACTION_REQUIRED errors. Providers that support refresh tokens can implement this as a no-op. Providers that require interactive re-authentication should initiate the appropriate flow (redirect, popup, etc.).

      Note: If this method redirects the page, it may never return. The app will reload after authentication completes and re-initialize with a fresh token.

      Returns Promise<void>

      Promise that resolves if re-auth completed, or never returns if redirected

    • Logout — clears all MJ client-side caches then delegates to the provider.

      Cache clearing happens universally regardless of auth provider so that a subsequent login as a different user never sees the previous user's data. Providers that need to clear additional caches should override logoutInternal() and call super.logoutInternal() if applicable.

      Returns Promise<void>

    • Provider-specific logout implementation

      Subclasses implement provider-specific logout flow (redirect, SDK logout, etc.). The base class logout() calls clearClientCaches() before invoking this method, so providers do NOT need to handle cache clearing themselves.

      Returns Promise<void>

    • 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

      const token = await this.authBase.refreshToken();
      return token.idToken; // Always succeeds or throws
    • Refresh token using provider-specific mechanism

      Implements the provider's token refresh logic using whatever mechanism is appropriate (silent refresh with refresh tokens, iframe-based token acquisition, etc.).

      Should return success with token if refresh succeeds, or failure with appropriate error type (TOKEN_EXPIRED, INTERACTION_REQUIRED, etc.) if refresh fails.

      Returns Promise<TokenRefreshResult>

      Promise resolving to TokenRefreshResult indicating success/failure