---
id: oauth-api
name: OAuth API
version: 1.0.0
summary: |
  External OAuth 2.0 and OIDC identity provider API used by BookWorm clients
  and services to authenticate users, issue tokens, and delegate agent access.
externalSystem: true
owners:
  - platform-engineering-team
badges:
  - content: External
    backgroundColor: purple
    textColor: purple
  - content: HTTP API
    backgroundColor: teal
    textColor: teal
styles:
  icon: /icons/third-party/entra-id.svg
---

## Integration Purpose & Boundary

OAuth API (backed by Microsoft Entra ID) is BookWorm's external OAuth 2.0 and OpenID Connect (OIDC) authentication boundary. Storefront and Backoffice clients authenticate users against it, while [[service|catalog-api]], [[service|basket-api]], [[service|order-api]], [[service|rating-api]], [[service|chat-api]], [[service|mcp-server]], and [[service|scheduler-service]] validate issued JWTs and use Entra Agent Identities for delegated On-Behalf-Of (OBO) calls.

:::warning
Authentication is not authorization: OAuth API verifies caller identity and issues role/scope claims (`customer`, `business_user`, `admin`), while each BookWorm service enforces its own resource-ownership and policy checks. Protected services must **fail closed** (`401 Unauthorized`) whenever token validation or provider metadata fails.
:::

## Integration Profile

| Property                         | Value                                                                                                                                                                                                          |
| :------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Provider / Sidecar**           | Microsoft Entra ID (OAuth 2.0 / OIDC & Entra Agent Identities)                                                                                                                                                 |
| **BookWorm Consumers**           | [[service\|catalog-api]], [[service\|basket-api]], [[service\|order-api]], [[service\|rating-api]], [[service\|chat-api]], [[service\|mcp-server]], [[service\|scheduler-service]], Storefront, and Backoffice |
| **Runtime Transport & Protocol** | HTTPS OAuth 2.0 / OIDC (proxied via API Gateway for browser flows; JWT & OBO token exchange for APIs)                                                                                                          |
| **Auth / Credential Boundary**   | Federated Managed Identity in publish environments; client secrets and signing tokens kept strictly out of source control and logs                                                                             |
| **Data / PII Sensitivity**       | High — carries user identity claims, access tokens, and session cookies; never log bearer tokens or refresh credentials                                                                                        |
| **Failure / Fallback Behavior**  | Fail-closed — protected APIs reject unauthenticated or unverifiable requests with `401 Unauthorized` without anonymous fallback                                                                                |

## Visualizations & Specifications

### Authentication & Delegation Context

<MermaidFileLoader file="mermaids/OAuthAPI-diagram-1.mmd" />

### Service Interactions

<NodeGraph />

<Accordion title="Application Roles & Service Scope Mapping">
	- **App roles:** `customer` (storefront shopping, orders, chat, and reviews), `business_user`
	(catalog writes), and `admin` (backoffice dashboards, moderation, and scheduler operations). -
	**Service scopes:** Each API enforces its own read/write scopes (`catalog_read`/`catalog_write`,
	`basket_read`/`basket_write`, `ordering_read`/`ordering_write`, `rating_read`/`rating_write`,
	`chatting_read`/`chatting_write`, `mcptools_read`).
</Accordion>

## Related Documentation

- [[doc|platform/006-api-and-contracts]] — Consolidated service authentication and route index.
- [[doc|platform/004-identity-and-rbac-matrix]] — Platform-wide Azure RBAC and Entra ID permissions.
- [[service|chat-api]] — Consumer of agent identity and OBO token exchange.
- [[service|rating-api]] — Consumer of agent identity and A2A read scope policy.
- [[system|identity-provider]] — External Identity Provider system boundary.
