Skip to content

Commit 5c70e92

Browse files
pktikkaniclaude
andcommitted
Add Azure AD authentication details to architecture docs
- Document Azure AD app registration settings - Add deployment branches table (main vs access-review) - Explain token validation flow with diagram - Document valid audiences configuration πŸ€– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7b277f5 commit 5c70e92

1 file changed

Lines changed: 46 additions & 7 deletions

File tree

β€Ždocs/ARCHITECTURE.mdβ€Ž

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,28 @@ export function parseGraphResponse<T>(
291291

292292
## Authentication Flow
293293

294-
### Azure AD Token Validation
294+
### Azure AD App Registration
295+
296+
This API is called by the **auditsphere-spfx** web part running in SharePoint Online. Authentication is handled via Azure AD.
297+
298+
**Azure AD App:** Document Intelligence API
299+
300+
| Setting | Value |
301+
|---------|-------|
302+
| Client ID | `eca12ded-8416-41fd-ac0a-ffaccb1ecb04` |
303+
| Application ID URI | `api://eca12ded-8416-41fd-ac0a-ffaccb1ecb04` |
304+
| Exposed Scope | `access_as_user` |
305+
306+
> **Important:** The Application ID URI must use the `api://{client-id}` format. The API validates tokens against this format in `src/trpc/init.ts`.
307+
308+
### Deployment Branches
309+
310+
| Branch | API URL | Purpose |
311+
|--------|---------|---------|
312+
| `main` | `https://auditsphere-api.nubewired.com` | All features |
313+
| `access-review` | `https://auditsphere-api-access.nubewired.com` | Access review only |
314+
315+
### Token Validation
295316

296317
```
297318
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
@@ -304,25 +325,43 @@ export function parseGraphResponse<T>(
304325
β”‚ β”‚ Web Part │◀────────│ (tenant) β”‚ β”‚
305326
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Token β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
306327
β”‚ β”‚
328+
β”‚ Token claims: β”‚
329+
β”‚ - aud: "eca12ded-8416-41fd-ac0a-ffaccb1ecb04" (client ID) β”‚
330+
β”‚ - scp: "access_as_user" β”‚
331+
β”‚ - preferred_username: "user@tenant.com" β”‚
332+
β”‚ β”‚
307333
β”‚ 2. SPFx sends token to API β”‚
308334
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
309335
β”‚ β”‚ SPFx │────────▢│ AuditSphere β”‚ β”‚
310336
β”‚ β”‚ Web Part β”‚ Bearer β”‚ API β”‚ β”‚
311337
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Token β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
312338
β”‚ β”‚
313-
β”‚ 3. API validates token β”‚
339+
β”‚ 3. API validates token (src/trpc/init.ts) β”‚
314340
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
315341
β”‚ β”‚ a. Fetch JWKS from Azure AD β”‚ β”‚
316-
β”‚ β”‚ b. Verify JWT signature β”‚ β”‚
317-
β”‚ β”‚ c. Check audience (client_id) β”‚ β”‚
318-
β”‚ β”‚ d. Check issuer (tenant) β”‚ β”‚
319-
β”‚ β”‚ e. Check expiration β”‚ β”‚
320-
β”‚ β”‚ f. Extract claims (userId, email, tenant) β”‚ β”‚
342+
β”‚ β”‚ b. Verify JWT signature (RS256) β”‚ β”‚
343+
β”‚ β”‚ c. Check audience ∈ [CLIENT_ID, api://CLIENT_ID] β”‚ β”‚
344+
β”‚ β”‚ d. Check issuer matches tenant β”‚ β”‚
345+
β”‚ β”‚ e. Extract user email β†’ find/create user in database β”‚ β”‚
321346
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
322347
β”‚ β”‚
323348
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
324349
```
325350

351+
### Valid Audiences
352+
353+
The API accepts tokens with either audience format:
354+
355+
```typescript
356+
// src/trpc/init.ts
357+
const validAudiences = [
358+
process.env.MICROSOFT_CLIENT_ID, // eca12ded-8416-41fd-ac0a-ffaccb1ecb04
359+
`api://${process.env.MICROSOFT_CLIENT_ID}`, // api://eca12ded-8416-41fd-ac0a-ffaccb1ecb04
360+
];
361+
```
362+
363+
SPFx uses `AadHttpClient.getClient(clientId)` which results in tokens with the raw client ID as the audience.
364+
326365
### Context Creation
327366

328367
```typescript

0 commit comments

Comments
Β (0)