π
Micro-Frontends: Authentication Magic at Dutch Railways
TABLE OF CONTENTS
Micro frontends
Module federation
MSAL authentication
Kubernetes config
Live application
04
05
01
02
03
Peter Eijgermans
CodeSmith / Architect
Full-Stack
Meet Petra - Train Controller
6:00 AM: Needs real-time train positions
6:15 AM: Emergency response required
6:30 AM: System takes 45 seconds to load each screen
6:31 AM: Frustration level: MAXIMUM
π€― 8:47 AM - Amsterdam Station Chaos
3,000 railway workers locked out
Authentication system: CRASHED
Rush hour:
IN PROGRESS
Punchline:
This is why weβre hereβ
to prevent such disasters
Show of Hands Time
πββοΈ "Who's afraid to deploy on Friday afternoon?"
πββοΈ "Who's maintaining multiple authentication systems?"
π "Who's dealing with a monolith that takes forever to build?"
The Railway Monolith: A Beautiful Disaster
Slow development/deployment
Not Maintainable
Hard to Scale
SPOF
"This HUGE app is like one giant box of LEGO that nobody can organize.
If one part of the app breaks? The whole thing crashes.οΏ½ If you want to add something new? You have to rebuild the whole box."
Monolith
Database
Massive Application
What If We Could..
Architecture: How to get from Monolith to Modular speed ?!
Authentication & Security:
These are the dreams of every team:
First, we want to build and improve fastβοΏ½ with smaller parts, easy to connect, no more crashes.
Then, we want users to log in just once,οΏ½
Today, Iβll walk through these pointsβ
and weβll check them off
Letβs go!
Architecture:
From Monolith to
Modular Speed !
Step 1 - Split frontend and backend
Database
Backend
Microservices
Frontend
Step 2 - Split backend as micro services
DB
DB
DB
DB
Backend
Microservices
Frontend
Step 3 - Split frontend -> Verticals
Frontend
Backend
Team A
Team A
C
B
B
DB
DB
DB
B
C
WS REST
pairing
Short definition
βAn architectural style where independently deliverable frontend and backend applications are composed into a greater wholeβ
Micro Frontends to the Rescue
Micro frontend architecture Dutch Railways
Host / Shell
Train
Tracking
Train /Track Tracking
Route Planning
Track Occupancy
Route Planning
Route Planning
Track Occupancy
Track Occupancy
FE
Track
Section
Track
Section
Track
Section
Train /Track Tracking
Route Planning
Track
Section
Micro Services
Track Occupancy
responsibilities:οΏ½1. routingοΏ½2. compositionοΏ½3. authentication
4. state mgmt
5. easy scaling
6. β¦..
WS
rest
HOST / SHELL
MF train tracking
MF route planning
MF track
section
Butβ¦
How to build the
Frontend efficiently?
Module Federation
2022 Webcomponents
Host / Shell
Train
Tracking
Train / Infra
Tracking
Route Mgmt
Track Occupancy
Route Mgmt
Route Mgmt
Track Occupancy
Track Occupancy
Track
Section
Track
Section
Track
Section
Angular
Angular
Angular
Angular
Angular
Angular
Angular
Angular
Angular
Angular
Angular
shared libs
shared libs
shared libs
π’ 50s load time
β Petra misses emergencies
2025 Module Federation for speed !!!
Host / Shell
Train
Tracking
Train / Infra
Tracking
Route Mgmt
Track Occupancy
Route Mgmt
Route Mgmt
Track Occupancy
Track Occupancy
Track
Section
Track
Section
Track
Section
Angular
Shared Lib
Independent Deployment/ CI CD
Technology Agnostic
Improved Scalability
π 0.5s load time β Petra saves the day
Performance
Module Federation is fast
Config Remote
Config Host
Config specific versions to share !
How does the Host
load
the Remotes?
Mid-talk Checkpoint
Architecture & Speed (Micro Frontends & Module Federation):
β
β
β
β
Demo
Module Federation !
"Breaking the system apart helped speed up developmentβ
but we still had a major problem left."
Authentication
The Multi-App Authentication Nightmare
Slow or broken SSO
Multiple logins
Token Chaos
CORS issues
Redirect loops
π¦ΈββοΈ The 2 Heroes of Modern Authentication
OpenID Connect (OIDC): Identity Layer
"OIDC is like showing your ID at the entranceβ
OAuth 2.1: The Delegation Protocol
"OAuth is like getting a festival wristband"
π«
Key Players:
π«
OIDC Flow
"Now let's see exactly how this OIDC flow works step by step.
Starting with what happens when a user clicks 'Login'..."
Flow 1: Initial Login & Authorization
π
βοΈ FIRST: needed auth-config MSAL
Authorization Server (EntraID - The Bouncer)
Part 1 β Part 2: "Great!
We have an authorization code.
Now let's see how we exchange it for tokens..."
Flow 2: Token Exchange & Caching
Authorization Server (EntraID - The Bouncer)
Token Types | Purpose | Where Used | Format | Lifetime | Example Scope Needed |
π«Access Token | Access to protected APIs | Sent in Authorisation headers as Bearer | JWT | ~1 hour | api://xyz/.default |
πToken | User identity info for authentication | Used by frontend | JWT | ~1 hour | |
πRefresh Token | Get new tokens without login.eEnables SSO! π― | Used internally | hidden | Long-lived | |
The Scope is a URL for specific permissions for an API
Part 2 β Part 3: "Perfect! We have our tokens cached in the browser! β local or sessionscopeοΏ½
Now let's see how our application uses them..."
Flow 3: API Calls & Token Management
π
The Magic:
Automatic token injection via HTTP interceptors!
Resource Server (Your API - The Bartender)
π
Token injection
GET /user/getDrink
Authorization: Bearer eyJ0eXAiOiJK...
Component
HTTP Interceptor
JWT Secured Resource Server
GET /user/getDrink
OIDC Flow - Key Takeaways!
π Login
User β EntraID β Authorization Code
π« Exchange
Authorization Code β 3 Tokens:
π Use
Access token β API calls (auto-refresh)
MSAL for OIDC
Key Benefit: MSAL abstracts away the complexity of token management, token renewal and token injection.
Now Let's See How MSAL Angular Handles This
MSAL AuthenticationResult Interface:
interface AuthenticationResult {
accessToken: string; // "eyJ0eXAiOiJKV1QiLCJhbGci..."
idToken: string; // Identity proof
refreshToken: string; // Renewal ticket
expiresOn: Date; // Expiration time
scopes: string[]; // Permissions granted
account: AccountInfo; // User profile information
}
MSAL Architecture
ποΈ Angular MSAL Architecture Overview
MsalService
Transition : "Now that we understand MSAL architecture, let's see how this looks in a real Angular component..."
Real-World
Login Component
ποΈ Building Your First MSAL Login Component
ποΈ Building Your First MSAL Login Component
Butβ¦
How do we share authentication across micro-frontends?
That's our next challenge..."
Challenge
β οΈ Key Risks:
οΏ½
Different Login Status in Each App
Multiple Tokens, Out of Sync
Problems Across Different Domains
Goal: SSO
Security Gaps
The Solution:
Share MSAL Packages
Module Federation Solution
π Sharing MSAL Packages in config HOSTοΏ½οΏ½
Key Concept:
Shared MSAL packages
ensure single instance !
Module Federation Solution
π Sharing MSAL Packages in REMOTE configοΏ½οΏ½
2025 Module Federation for speed !!!
Host / Shell
Train
Tracking
Train / Infra
Tracking
Route Mgmt
Track Occupancy
Route Mgmt
Route Mgmt
Track Occupancy
Track Occupancy
Track
Section
Track
Section
Track
Section
Angular
MSAL
How to config SSO?
βοΈ Same auth-config for all Micro frontends !
ποΈ Same OIDC Module - The Foundation for OIDC
π Same MSAL Instance config!
HTTP Interceptor Configuration
Magic: Automatically adds Authorization: Bearer <token> header
π Automatic Token Injection:
SSO Checklist !
β Same Identity Provider (EntraID)
β Shares MSAL Package and storage
β Same auth config
β Single Token Refresh Strategy
Demo SSO !
Websockets for real time data
What are Websockets ?
Network protocol
Two-way communication
Data is pushed to client
Always Open
π WebSocket Authentication Challenge #3
The Problem: Websockets do not support HTTP headers for tokens authentication tokens!
π WebSocket Authentication Challenge
The Solution β Custom authentication handling !
msalService
Final Checkoff
Authentication & Security (MSAL & Auth Solutions):
β
β
β
β
Mission Completed !
Final Challenge:
Kubernetes Config
β One App, Many Environments?
βοΈ MSAL auth-config example
βοΈ Kubernetes ConfigMap
Runtime Config Flow (High-level)
1. K8s ConfigMap
provides
app-config.json per Env
2.Load Config
fetch(app-config.json)
new AppConfig()
setup.ts
3. InjectionToken
APP_CONFIG
DI System
bootstrap.ts
4. MSAL Setup
Factory Functions:
β’ MSALInstance
β’ Guard & Interceptor
Kubernetes advantages !
β Settings stored in Kubernetes, not in the app
β Change config without rebuilding
β One app on different Environments
One app, many environmentsβno rebuilds
REAL WORLD APP
Trackviewer is micro frontend-based app for the Dutch Railway.
With Trackviewer you can see at a glance where exactly trains are, what the delay is and from which track they will disappear.
Remember Petra ?
βCall to Actionβ :
Claim one whole day,
Try Module Federation
and implement MSAL for seamless OIDC flows
βCall to Actionβ :
Claim one whole day,
Try Module Federation
and implement MSAL for seamless OIDC flows
GrΓ cies !
Peter Eijgermans
CodeSmith / Architect
Full-Stack
Peter Eijgermans
π Bootstrapping the Shell Application
Key Point:
MsalRedirectComponent handles OAuth callback
π― Silent First, Interactive Fallback
Strategy:
Always try silent first, fallback to interactive
π Security Best Practices
β What We're Doing Right:
π¨ Watch Out For:
Common Problems & Solutions:
1. "MSAL instance not initialized"
// Ensure initialization in BearerTokenService
await this.authService.instance.initialize();
2. Module Federation version conflicts
// Use singleton and strict versions
shared: {
'@azure/msal-angular': { singleton: true, strictVersion: true }
}
Common Problems & Solutions:
3. WebSocket authentication failures
typescript
// Check token expiration before sending
if (tokenResult.expiresOn < new Date()) {
tokenResult = await this.bearerTokenService.acquireToken();
}
4. Redirect loops
typescript
// Ensure proper redirect URI configuration
redirectUri: `${location.origin}${location.pathname}`
Key takeaways
π Security: MSAL simplifies the complexity of implementing OAuth/OIDC
π§© Scalability: Module Federation enables distributed auth
β‘ Performance: Shared packages, single MSAL instance
π Flexibility: Custom services for WebSocket auth
π οΈ Maintainability: Environment-specific configurations in K8s
π« Custom Token Service for WebSockets
OIDC Flow: π« Getting the golden ticket
We have 3 Types of Tokens:
Grants access to protected APIs
Grants access to protected APIs
The Magic of Injection Tokens
The APP_CONFIG injection token acts as a bridge between your external configuration (from K8s) and Angular's DI system
The Magic of Injection Tokens
Step-by-step flow:
π‘οΈProtecting Routes with MSAL Guard
MSAL coding - Key Takeaways!
β OIDC Module configures MSAL for Angular/React
β MSALInterceptorConfigProvider contains list protected resources
β Custom Token Service for WebSockets
β Share MSAL packages with Module Federation
Challenge 4: How to Solve the Multi-Environment Authentication ?
Problem:
Hard-coded authentication configuration
Different environments need different MSAL settings
Solution:
Single build artifact
Dynamic configuration Kubernetes Configsmaps
Type-safe injection
Traditional Approach:
Build per Environment
Hard-coded config
Deployment complexily
Micro frontends - Key Takeaways!
β Understand the Micro frontend Architecture
β Host vs. Remote applications
β Configure and Share resources with Module Federation