XSUAA — Authorization & Trust Management
SAP BTP's OAuth 2.0 authorization server — the engine behind all BTP application security. Manages scopes, role templates, role collections, and JWT token issuance for every BTP application.
Executive Summary
XSUAA (Extended Services for User Account and Authentication) is SAP BTP's OAuth 2.0 Authorization Server. It issues JWT access tokens that contain user identity, tenant information, and granted scopes. Every BTP application must be registered in XSUAA (via xs-security.json), and every service call must validate the JWT token before granting access to resources.
XSUAA is not a user store — it delegates authentication to SAP IAS. XSUAA's role is exclusively authorization: deciding what an authenticated user is permitted to do based on their assigned scopes and role collections.
XSUAA Architecture Concepts
xs-security.json — Complete Application Security Descriptor
$XSAPPNAME placeholder is replaced with the actual xsappname at runtime.1{
2 "xsappname": "dewa-utilities-portal",
3 "tenant-mode": "dedicated",
4 "description": "DEWA Utilities Customer Portal",
5 "scopes": [
6 {
7 "name": "$XSAPPNAME.customer.read",
8 "description": "Read customer utility data"
9 },
10 {
11 "name": "$XSAPPNAME.billing.read",
12 "description": "View billing statements"
13 },
14 {
15 "name": "$XSAPPNAME.billing.admin",
16 "description": "Manage billing corrections"
17 },
18 {
19 "name": "uaa.user",
20 "description": "UAA user scope (required)"
21 }
22 ],
23 "role-templates": [
24 {
25 "name": "CustomerViewer",
26 "description": "Read-only customer access",
27 "scope-references": [
28 "$XSAPPNAME.customer.read",
29 "$XSAPPNAME.billing.read"
30 ]
31 },
32 {
33 "name": "BillingAdministrator",
34 "description": "Full billing administration",
35 "scope-references": [
36 "$XSAPPNAME.customer.read",
37 "$XSAPPNAME.billing.read",
38 "$XSAPPNAME.billing.admin"
39 ]
40 }
41 ],
42 "role-collections": [
43 {
44 "name": "DEWA-Customer-Viewer",
45 "description": "Standard customer service agent",
46 "role-template-references": [
47 "$XSAPPNAME.CustomerViewer"
48 ]
49 }
50 ],
51 "oauth2-configuration": {
52 "token-validity": 3600,
53 "refresh-token-validity": 86400,
54 "redirect-uris": [
55 "https://dewa-utilities.cfapps.ae1.hana.ondemand.com/login/callback"
56 ]
57 }
58}CAP Service Authorization — Declarative Pattern
@restrict annotation is the recommended pattern for CAP applications. It is enforced at the OData protocol layer — before any application code runs — and is visible in the service definition for auditors.1// CAP service — scope-based authorization
2// srv/billing-service.cds
3service BillingService @(requires: 'authenticated-user') {
4 @(restrict: [
5 { grant: 'READ', to: 'CustomerViewer' },
6 { grant: ['READ', 'WRITE', 'DELETE'], to: 'BillingAdministrator' }
7 ])
8 entity Bills as projection on db.Bills;
9
10 @(requires: 'BillingAdministrator')
11 action applyCorrection(billId: UUID, amount: Decimal) returns Boolean;
12}Manual Scope Check — Node.js (@sap/xssec)
1// Node.js manual scope check (for non-CAP services)
2const xssec = require('@sap/xssec');
3const xsuaaCredentials = JSON.parse(process.env.VCAP_SERVICES).xsuaa[0].credentials;
4
5app.get('/api/admin', (req, res) => {
6 xssec.createSecurityContext(
7 req.headers.authorization?.split(' ')[1],
8 xsuaaCredentials,
9 (err, ctx) => {
10 if (err || !ctx.checkScope('$XSAPPNAME.billing.admin')) {
11 return res.status(403).json({ error: 'Insufficient scope' });
12 }
13 // Proceed with admin logic
14 }
15 );
16});JWT Token Claims Reference
| JWT Claim | Description | Example |
|---|---|---|
| user_name | User login name (email) | ahmed.ali@dewa.gov.ae |
| given_name | First name from IAS/IdP | Ahmed |
| xsappname | XSUAA application name | dewa-utilities-portal!t123 |
| scope | Array of granted scope strings | ["dewa...!t123.billing.read"] |
| zid | Zone ID (XSUAA tenant ID) | a1b2c3d4-... |
| ext_attr.subaccountid | BTP subaccount ID | sa-12345-... |
| exp | Token expiry (Unix timestamp) | 1748980800 (3600s from iat) |
Enterprise Example: DEWA Utilities Portal
Best Practices
Avoid a single admin scope for all privileged actions. Break permissions down by domain and action (customer.read, billing.read, billing.admin) to enable least-privilege RBAC.
Declarative scope checks via @restrict are safer and more auditable than imperative xssec calls. CAP enforces them automatically at the OData layer.
One hour is the maximum acceptable token validity for user tokens. Shorter is better — implement token refresh rather than extending validity.
Service-to-service calls must use Client Credentials grant type (no user token). Never impersonate user tokens for backend communication.
Token validation must happen on every HTTP request — never cache scope decisions across requests. CAP does this automatically when XSUAA is bound.
Common Pitfalls
JWT Security Controls
JWT tokens are bearer tokens — anyone with the token can use it. Apply these controls to limit blast radius: