Member Junction
    Preparing search index...

    Interface for Angular authentication providers - v3.0.0

    This interface defines the contract that all auth providers must implement. It ensures consistent behavior across different OAuth providers while hiding provider-specific implementation details.

    • Removed: getUserProfile() - Use getUserInfo() instead
    • Removed: getUser() - Use getUserInfo() instead
    • Removed: getUserClaims() - Use getTokenInfo() instead
    • Removed: getToken() - Use getIdToken() instead
    • Removed: refresh() - Use refreshToken() instead
    • Removed: checkExpiredTokenError() - Use classifyError() instead

    3.0.0

    interface IAngularAuthProvider {
        type: string;
        classifyError(error: unknown): StandardAuthError;
        getIdToken(): Promise<string | null>;
        getRequiredConfig(): string[];
        getTokenInfo(): Promise<StandardAuthToken | null>;
        getUserEmail(): Observable<string>;
        getUserInfo(): Observable<StandardUserInfo | null>;
        handleCallback(): Promise<void>;
        initialize(): Promise<void>;
        isAuthenticated(): Observable<boolean>;
        login(options?: Record<string, unknown>): Promise<void> | Observable<void>;
        logout(): Promise<void>;
        refreshToken(): Promise<StandardAuthToken>;
        validateConfig(config: Record<string, unknown>): boolean;
    }

    Implemented by

    Index

    Properties

    type: string

    Provider type identifier (e.g., 'msal', 'auth0', 'okta')

    Methods

    • Classify an error into a standard error type

      This method converts provider-specific errors into semantic error types that application code can handle consistently. Eliminates the need for consumers to check provider-specific error names like 'BrowserAuthError'.

      Parameters

      • error: unknown

        The error to classify (can be any type)

      Returns StandardAuthError

      StandardAuthError with categorized error type

      try {
      await this.authBase.login();
      } catch (err) {
      const authError = this.authBase.classifyError(err);

      switch (authError.type) {
      case AuthErrorType.TOKEN_EXPIRED:
      // Show "session expired" message
      break;
      case AuthErrorType.USER_CANCELLED:
      // User cancelled - don't show error
      break;
      default:
      // Show generic error
      alert(authError.userMessage);
      }
      }
    • Get the current ID token as a string

      This is the primary method applications should use to get the token for backend API calls. It abstracts away provider-specific token storage (Auth0's __raw vs MSAL's idToken).

      Returns Promise<string | null>

      Promise resolving to the ID token string, or null if not authenticated

      const token = await this.authBase.getIdToken();
      if (token) {
      // Use token for GraphQL or REST API calls
      setupGraphQLClient(token, apiUrl);
      }
    • Get list of required configuration fields for this provider

      Returns string[]

      Array of required config field names

      // Auth0 requires: ['clientId', 'domain']
      // MSAL requires: ['clientId', 'tenantId']
    • Get complete token information

      Returns a standardized token object with ID token, access token, and expiration. Use this when you need more than just the token string.

      Returns Promise<StandardAuthToken | null>

      Promise resolving to StandardAuthToken or null if not authenticated

      const tokenInfo = await this.authBase.getTokenInfo();
      if (tokenInfo) {
      console.log(`Token expires at: ${new Date(tokenInfo.expiresAt)}`);
      }
    • Observable stream of user's email address

      Emits email string when authenticated, empty string otherwise.

      Returns Observable<string>

      this.userEmail$ = this.authBase.getUserEmail();
      
    • Observable stream of authentication state

      Emits true when user is authenticated, false otherwise. Subscribe to this for reactive UI updates.

      Returns Observable<boolean>

      this.authBase.isAuthenticated().subscribe(isAuth => {
      this.showLoginButton = !isAuth;
      });
    • Initiate login flow

      Parameters

      • Optionaloptions: Record<string, unknown>

        Optional provider-specific login options

      Returns Promise<void> | Observable<void>

      Observable for backward compatibility, can also return Promise

      await this.authBase.login({ appState: { target: '/dashboard' } });
      
    • Refresh the current 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 a fresh token 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