API Reference
The Application Service (Services/BlazorBlueprint.InternalApi) is a separate ASP.NET Core Web API process. The web app calls it over HTTP with a JWT, and every call carries the organisation it acts for.
Where It Sits
| Service | Port | Reachable from |
|---|---|---|
| Web app (Blazor Server) | 8080 | Published — the only port published to the network |
| Application Service | 8081 | The compose network only |
It runs only in the Full topology. Under Lite (Services:InternalApi:Enabled is false) the Web host serves plugin REST endpoints (/api/plugin/*) itself and mints the service token in-process (LocalServiceTokenProvider); /api/token is not served there, because the client secret ships blank and a public token endpoint would hand a service token to anyone. See Deployment.
Every host maps /health (readiness) and /alive (liveness), and the Application Service answers GET / with a minimal anonymous status object for uptime monitors. Swagger UI is at /swagger in Development, or wherever Swagger:Enabled is true — leave it off in production, since it documents your whole API surface. Platform administrators see each service’s state and the running configuration at /Platform/Infrastructure.
Scoped Controllers
Every authorized controller declares which tenant scope it serves. The two base classes in BlazorBlueprint.Api.Shared declare it for you; both carry [Authorize(AuthenticationSchemes = ApiContractNames.BearerScheme, Policy = ApiContractNames.ServiceClientPolicy)] and the route api/[controller].
A plugin controller should not inherit them: that route serves it at /api/{Controller}, outside the /api/plugin/ prefix the plugin availability and entitlement gates key on. A plugin derives from ControllerBase and declares its own route and attributes — see Plugins. A tenant-scoped controller on a route outside api/plugin/ gets no tenant, so its repository calls throw. [EndpointAudience] decides which process serves a plugin controller.
Organisation-scoped
Inherit OrganisationApiController ([EndpointScope(EndpointScope.Organisation)]). The request must carry a service token (401 without one) and send X-Organisation-Id; ApiTenantResolutionMiddleware checks it against the token, resolves the organisation and sets the tenant context, so every IRepository<T> call is scoped to that organisation’s database.
public class MyController : OrganisationApiController{ // CurrentOrganisationId and CurrentOrganisationName are available. // IRepository<T> queries are scoped to this organisation's database.}Platform-scoped
Inherit PlatformApiController ([EndpointScope(EndpointScope.Platform)]). No tenant is set, and the token must be minted without an organisation: no token gets 401 unless the endpoint is [AllowAnonymous], as the token endpoint is, and an organisation-bound token gets 403. Use IPlatformRepository<T>.
[AllowAnonymous]public class TokenController : PlatformApiController{ // No tenant context; uses IPlatformRepository<T>}An authorized endpoint that declares neither scope is refused with 500. Without a scope, any valid token — including one bound to another organisation — could call it unchecked, so the middleware fails closed.
Authentication
Service-to-service (Web → API)
The web app authenticates with client credentials:
POST /api/token{ "ClientId": "blazorblueprint-web", "ClientSecret": "...", "OrganisationId": "<org-id>" // optional; needed for organisation-scoped calls}
→ 200 { "token": "<jwt>", "expiresIn": 3600 }
# Subsequent requests:Authorization: Bearer <jwt-with-org_id-claim>X-Organisation-Id: <same-org-id>Each token is bound to one organisation by an org_id claim, and a request whose X-Organisation-Id doesn’t match is rejected, so a leaked token can act only on its own organisation. A token minted without OrganisationId works only on platform-scoped endpoints. Every token carries the ServiceClient role the ServiceClient policy requires. expiresIn is in seconds.
The API host signs and validates tokens with Security:Jwt:*:
| Key | Shipped | Notes |
|---|---|---|
SecretKey |
blank | Required, at least 32 characters (HMAC-SHA256). The host refuses to start without it. |
Issuer |
BlazorBlueprint.InternalApi |
Required. |
Audience |
BlazorBlueprint.Web |
Required. |
ExpiryMinutes |
60 |
1 to 1440. |
On the web side:
- Your typed client stamps
X-Organisation-Id, reading the organisation fromITenantContextin the caller’s scope (seeExampleApiClientin the example plugin). JwtAuthenticationHandlerreads that header back and attaches the matching token fromIJwtTokenApiClient, which caches one token per organisation and renews it five minutes before expiry (or halfway through, for tokens shorter than ten minutes). On a401it refreshes and retries the whole request once, body included.
Don’t read the tenant inside the handler. IHttpClientFactory builds the handler chain in its own DI scope, so a scoped ITenantContext there is not the caller’s. On a Blazor circuit it is empty, a platform token is minted, and every organisation-scoped call gets 403. Read the organisation in the typed client and pass it on the request.
Configuration: the web host sends Services:InternalApi:ClientId and Services:InternalApi:ClientSecret; the API host checks them against Security:WebApp:ClientId and Security:WebApp:ClientSecret. The client id ships as blazorblueprint-web on both. The secret is one shared value that ships blank — keep it in an environment variable or secret store, never a committed file. See Configuration → InternalApi Credentials.
Writing your own controller: two rules that fail silently
These matter for controllers outside the base classes — such as one in the Web host, which is where a public or partner endpoint belongs, since the Application Service publishes no port.
1. A controller with no authorization attribute is anonymous. The Web host has no fallback authorization policy, so omitting the attribute publishes the endpoint. Put an [Authorize…] attribute or an explicit [AllowAnonymous] on every controller; ControllerAuthorizationCoverageTests fails the build on one with neither.
2. The membership wall does not reliably cover /api. The anonymous wall lets every /api/* request through. A signed-in non-member gets 403 on /api/* for every organisation except the platform organisation, where the wall blocks only the member root segments (/admin, /apps, /plugin, /notifications). Being signed in is not being a member: put [AuthorizeOrganisationMember] on any controller serving tenant data.
[AuthorizeOrganisationMember] is a real tenancy check: the MEMBER role comes from the caller’s Active membership (not Suspended or Invited) of the organisation this request resolved to. Like [AuthorizeOrganisationAdmin], it also admits PLATFORMADMIN, so an operator can support an organisation while Security:PlatformAdmin:OrgImpersonation is on.
Don’t compose the role list by hand. [Authorize(Roles = MEMBER + "," + PLATFORMADMIN)] is equivalent today but won’t follow the attribute if it changes; the same coverage test fails the build on it.
A token-authenticated controller in the Web host also needs its scheme registered without making it the default — AddPluginApiJwtAuthentication() (or an API-key handler registered the same way), never AddJwtAuthentication(), which makes bearer the default and signs every page out — and must name that scheme on the controller, or it is evaluated against the cookie and refuses a valid token.
SignalR hubs
Middleware runs only for a hub’s handshake, so the access gates skip hub paths. A hub declares its own scope with [EndpointScope(EndpointScope.Organisation)] or [EndpointScope(EndpointScope.Platform)]; a plugin hub declaring neither is refused at connect, and a hub declaring one refuses any connection without a valid hub token. See Plugins.
Current Endpoints
| Method | Route | Scope | Description |
|---|---|---|---|
POST |
/api/token |
Platform | Client-credentials token exchange |
GET |
/api/organisations/current |
Organisation | id, name, isPlatform, isActive and createdAt of the token’s organisation |
That is deliberately the whole shipped surface: a worked example of the pattern, not a product API. Replace OrganisationsController with your own controllers on the two base classes.
The example plugin shows the pattern from a plugin: GET /api/plugin/exampleplugin/api-cache (organisation-scoped) and a CRUD controller at /api/plugin/exampleplugin/items (GET, GET/PUT/DELETE {number}, POST), each declaring its own [Route] and authorization. Plugin endpoints are served by this host under Full and by the Web host under Lite, and pass the same availability, install and entitlement checks as the plugin’s pages. A [EndpointScope(EndpointScope.Platform)] plugin endpoint runs for no organisation, so, like a /platform/plugin/* page, it answers only to the plugin being loaded, enabled and available at Platform → Apps.
Errors & Status Codes
| Status | When |
|---|---|
400 |
/api/token body is not a JSON object, or names an organisation that doesn’t exist or isn’t active; an organisation-scoped request lacks X-Organisation-Id or names one that can’t be resolved. |
401 |
Missing, expired or invalid bearer token; wrong client credentials at /api/token. |
403 |
Token without the ServiceClient role; org_id doesn’t match X-Organisation-Id; an organisation-bound token on a platform-scoped endpoint; a premium plugin’s /api/plugin/* endpoint for an organisation whose plan excludes it. |
404 |
A /api/plugin/* endpoint whose plugin is unavailable, not installed for the organisation, or platform-only. |
429 |
More than 10 /api/token requests a minute from one IP for one organisation id, or more than 5,000 a minute from one IP across all of them. |
500 |
An authorized endpoint declares no tenant scope, or both. (With Security:WebApp:ClientId or ClientSecret unset, the service refuses to start.) |
Tenant-resolution failures and a non-object /api/token body return ASP.NET Core problem details; otherwise /api/token returns { "message": … }. In your own controllers, log exception detail server-side and return something the caller can act on.
Don’t confirm that another tenant’s data exists. Return 404 for an entity outside the current tenant, exactly as if it didn’t exist. “Wrong organisation” instead of “not found” is an enumeration oracle.
Caching Responses
The Application Service runs ASP.NET Core output caching. Nothing is cached unless an action carries [OutputCache] naming one of the two policies in CachePolicyNames (BlazorBlueprint.Api.Shared). Use the constants: a misspelt name silently caches nothing.
| Policy | Key | Use |
|---|---|---|
CachePolicyNames.PerOrganisation |
host + resolved organisation (+ caller) | The default. Caches nothing when no organisation was resolved, so use it on organisation-scoped endpoints. |
CachePolicyNames.SharedAcrossOrganisations |
host (+ caller) | A response with nothing tenant-specific. One entry serves every organisation, so adding a field to such a response is a security review. Unused in the template. |
Both add the authenticated caller to the key, ignore the query string, cache only GET and HEAD, and expire after Caching:DefaultCacheDurationSeconds (60 shipped). With Caching:UseRedisDistributedCache on, entries live in Redis. The example plugin’s api-cache endpoint uses PerOrganisation.
Versioning & Rate Limiting
No versioning ships: the web app is the service’s only caller.
/api/token is rate-limited to 10 requests a minute per client IP and requested organisation id — it is the one endpoint reachable without a token, so it is where a client secret would be brute-forced. Because the organisation id is caller-chosen, a ceiling of 5,000 a minute per IP across all ids bounds what inventing ids buys. That ceiling is high because a Web replica re-mints a token for every active organisation after a restart. Nothing else in this service is throttled, since nothing else is reachable without a token.
The Web host’s endpoints are throttled. /api/files/* always, and /api/plugin/* under Lite (where the Web host serves it), fall under the Web host’s global per-client budget, RateLimiting:PermitLimitPerMinute (100), answering 429 beyond it. A page showing many stored files, or a plugin client calling its API in a loop, shares that budget with the caller’s page loads. See Configuration → Authentication.
When you expose an API to anyone else:
- Versioning — a route prefix (
/api/v1/…) is the least surprising choice and works with both base controllers. - Rate limiting — use the shared
IRateLimitStore(Redis-backed when Redis is present), not an in-memory counter, which lets N instances allow N× the requests. - Authentication — don’t hand the internal service JWT to an external caller: it is one deployment-wide identity with no revocation. Issue a per-organisation API key, store only its hash (
ITokenHasher), and revoke it by deleting the row.
Outbound provider calls already go through a shared policy stack with timeout, retry, circuit breaker and per-provider rate limiting. See Configuration → Outbound HTTP Policy.