An open API service indexing awesome lists of open source software.

https://github.com/coreprocess/entra-spa-widgets-poc


https://github.com/coreprocess/entra-spa-widgets-poc

Last synced: 9 months ago
JSON representation

Awesome Lists containing this project

README

          

# ๐Ÿ” Entra SPA Widgets POC

This project demonstrates a secure architecture for integrating multiple widget apps (micro frontends) into a central single-page portal app using Azure Entra ID (Microsoft identity platform). Each component is isolated and protected by its own app registration and access token.

![Screenshot](screenshot.png)

---

## ๐Ÿ“† Project Structure

```
.
โ”œโ”€โ”€ portal/
โ”‚ โ”œโ”€โ”€ app/ # SPA with MSAL.js login and widget iframes
โ”‚ โ””โ”€โ”€ service/ # Express backend protected by Entra access token
โ”œโ”€โ”€ widget1/
โ”‚ โ”œโ”€โ”€ app/ # Static frontend served via iframe
โ”‚ โ””โ”€โ”€ service/ # Token-protected API for Widget1
โ”œโ”€โ”€ widget2/
โ”‚ โ”œโ”€โ”€ app/ # Static frontend served via iframe
โ”‚ โ””โ”€โ”€ service/ # Token-protected API for Widget2
โ”œโ”€โ”€ scripts/
โ”‚ โ””โ”€โ”€ setup-azure-apps.sh # Automates Entra app registrations and config
โ”œโ”€โ”€ pnpm-workspace.yaml
โ””โ”€โ”€ package.json
```

---

## โš™๏ธ Prerequisites

* Node.js + PNPM
* Azure CLI with access to create AAD app registrations
* [`jq`](https://stedolan.github.io/jq/) and `uuidgen` installed
* Developer tenant or test Entra environment

---

## ๐Ÿš€ Setup

1. **Provision Azure Entra app registrations**:

```bash
az login
./scripts/setup-azure-apps.sh
```

This will:

* Register 3 apps: Portal, Widget1, Widget2
* Assign scopes and pre-authorized apps
* Set `accessTokenAcceptedVersion = 2`
* Write `config.js` into each frontend/backend folder

2. **Install dependencies and start all apps**:

```bash
pnpm install
pnpm dev
```

This will run:

* Portal on `http://localhost:3000`
* Widget1 on `http://localhost:3001`
* Widget2 on `http://localhost:3002`
* Each backend on ports `3100`, `3101`, and `3102` respectively

---

## ๐Ÿงช How It Works

* The **portal SPA** logs in the user using `msal-browser` (popup)
* It obtains access tokens for:

* Its own API
* Widget1 and Widget2 APIs
* It sends tokens to the widgets using `postMessage`
* Each widget uses the received token to call its own backend
* All backends validate the token using `jwks-rsa` and Entra public keys

---

## ๐Ÿ”’ Security Notes

* All access tokens are v2.0 and scoped to the specific app
* Each API checks the `aud` (audience) and `iss` (issuer) claim
* Each API also checks the `scp` claim matches the expected scope (e.g. `access_as_user`)
* CORS is configured to allow only frontend origin access
* No secrets are used; only public SPA flows

---

## ๐Ÿšœ Cleanup

To remove all created Entra apps, manually delete them via Azure Portal. All created Entra apps are prefixed with "Pre-Auth-App-Test".

---

## ๐Ÿ“Ž Related

* [MSAL.js Docs](https://github.com/AzureAD/microsoft-authentication-library-for-js)
* [Microsoft Identity Platform Overview](https://learn.microsoft.com/en-us/azure/active-directory/develop/)
* [Entra ID App Manifest Reference](https://learn.microsoft.com/en-us/azure/active-directory/develop/reference-app-manifest)