Authentication
Apso lets the generated service enforce authentication while your product controls who issues sessions or tokens. Choose the provider based on the client and trust boundary, then map the authenticated identity into tenant scope and roles.
- 01ClientServer component, mobile app, or service
- 02SDK or RESTTyped operation and validated payload
- 03IdentitySession, JWT, or API key context
- 04Tenant scopeAuthorization and row boundary
- 05ServiceGenerated route, product logic, and database
Supported strategies
| Strategy | Providers | Use |
|---|---|---|
| Database session | better-auth, custom-db-session | Web applications with server-managed sessions and user records. |
| JWT | auth0, clerk, cognito | Products that already issue signed user tokens through an identity provider. |
| API key | api-key | Service-to-service requests tied to an API-key entity. |
This .apsorc configuration controls generated application authentication. A hosted Apso service key is managed separately in the Apso Cloud API Keys view.
Better Auth
Use Better Auth for a database-backed session model owned by the application:
{
"auth": {
"provider": "better-auth",
"sessionEntity": "Session",
"userEntity": "User",
"accountUserEntity": "AccountUser",
"organizationField": "organizationId",
"roleField": "role"
}
}The entity names must match the models in the schema. The generated auth guard resolves the session into a normalized request context with user, organization, and role information.
JWT provider
Use a JWT strategy when Auth0, Clerk, or Cognito issues the user token. Configure the issuer, audience, and claim paths used by the product:
{
"auth": {
"provider": "auth0",
"jwt": {
"issuer": "https://your-tenant.example.com/",
"audience": "https://api.example.com",
"algorithms": ["RS256"]
},
"claims": {
"userId": "sub",
"email": "email",
"workspaceId": "org_id",
"roles": "roles"
},
"userEntity": "User"
}
}The provider can supply jwksUri. When omitted, the generated strategy derives the standard JWKS location from the issuer.
Application API key
Use this strategy for machine identities represented in the service schema:
{
"auth": {
"provider": "api-key",
"apiKeyHeader": "x-api-key",
"apiKeyEntity": "ApiKey",
"workspaceField": "workspaceId",
"roleField": "role"
}
}Store only a hash of a credential when implementing the ApiKey entity and its extensions. Return the raw value once at creation time.
Authentication and tenant scope
scopeBy uses values from the normalized auth context. For a workspace-scoped entity:
{
"name": "Project",
"scopeBy": "workspaceId",
"fields": [
{ "name": "name", "type": "text" }
]
}The auth strategy must populate workspaceId for the generated scope guard to filter reads, inject scope on creates, and verify ownership on updates and deletes.
Authentication proves the caller’s identity. Authorization still requires tenant scope, role checks, and product-specific rules. Test cross-tenant reads and writes before deployment.
Client boundary
Web with BFF
Keep service credentials in the BFF. Forward the user’s session or apply server-side authorization before calling the generated API.
Verification checklist
- Generate the auth guard and inspect its expected headers or cookie.
- Verify a valid caller can read one authorized resource.
- Verify a missing or invalid credential is rejected.
- Verify a caller cannot cross the configured tenant scope.
- Verify role bypasses are limited and covered by tests.