Readonly typeProvider type identifier (e.g., 'msal', 'auth0', 'okta')
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'.
The error to classify (can be any type)
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).
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 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.
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 profile information
Emits StandardUserInfo when authenticated, null otherwise. This replaces the old getUserProfile() which returned 'any'.
this.authBase.getUserInfo().subscribe(user => {
if (user) {
console.log(`Welcome ${user.name}!`);
}
});
Observable stream of authentication state
Emits true when user is authenticated, false otherwise. Subscribe to this for reactive UI updates.
this.authBase.isAuthenticated().subscribe(isAuth => {
this.showLoginButton = !isAuth;
});
Initiate login flow
Optional options: Record<string, unknown>Optional provider-specific login options
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.
Promise resolving to StandardAuthToken or throws on failure
const token = await this.authBase.refreshToken();
return token.idToken; // Always succeeds or throws
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.
Breaking Changes from v2.x:
Version
3.0.0