ERPClimb logoERPClimb
BTP Security
BTP & Integrationadvanced 4 min read

BTP Security Part 3: App-to-App Security with OAuth2

Lessons are open to try during our launch period. Some advanced content may move to Pro later. AI practice limits apply separately.

Key takeaway

Secure service-to-service communication: OAuth2 client credentials for technical calls, token exchange/JWT bearer to propagate user identity, granting scopes to other apps (foreign scopes), X. 509 credentials instead of secrets, and troubleshooting token errors.

In this lessonShow sections

Visual overview

APP-TO-APPChoosing the OAuth2 flow between servicesTechnical call or user propagation1App A calls app BService-to-service requestCall?B needs the user identity?User authorizations or auditNo → client credentials (technical)Yes2Token exchange / JWT bearerUser token exchanged for B's audienceExchange?Scopes granted?B grants scope to ANo → 403; add grantYesB authorizes the userData restricted by user attributesOKTip: decode the token when debugging — issuer, audience and scopes explainmost errors.

The situation: a real project scenario

A reporting service called an orders API with client credentials, so all users saw all countries' data. Switching to token exchange let the orders API apply the user's country attribute.

Explanation

Part 2 configured security for a single application; this part covers securing calls between two applications using OAuth2. With the client credentials flow, app A obtains a token as itself and calls app B in a purely technical context, with no end user involved.

With token exchange, also called JWT bearer, app A instead exchanges the calling user's own token, so that app B sees the real user rather than app A acting on its behalf. For either flow to work, app B has to grant the relevant scopes to app A — done through mechanisms like grant-as-authority-to-apps or foreign-scope references in xs-security.json.

On the credential side, X.509-based certificates are a way to avoid relying on long-lived client secrets.

The key design decision is whether the call genuinely needs the user's own context: using client credentials when user context is actually required strips out user-level authorization checks that the back end would otherwise apply. Long-lived client secrets copied into many different places are a particular leakage risk, which is why rotating them regularly, or switching to certificates, is worth doing. When something isn't working, decoding the token and checking its issuer, audience, scopes and expiry is usually the fastest way to find the cause.

A reasonable exercise is to grant a scope from app B to app A, call B using client credentials, and then call B again using token exchange, comparing the two tokens side by side. The checkpoint is that app B sees the technical client in the first case and the real user in the second.

Expert visual walkthrough

BTP ACADEMY · PART 3 · Integration pathERPClimb.com

App-to-app OAuth

BTP Security · Chapter-specific technical teaching map

Integration path

1Concept

Calling workload

2Concept

Token endpoint

3Concept

Service binding / destination

4Concept

Protected API

Tutor's chapter takeaway

Secure service-to-service communication: OAuth2 client credentials for technical calls, token exchange/JWT bearer to propagate user identity, granting scopes to other apps (foreign scopes), X.509 credentials instead of secrets, and troubleshooting token errors.

In a real project

A reporting service called an orders API with client credentials, so all users saw all countries' data. Switching to token exchange let the orders API apply the user's country attribute.

Watch out for

• Client credentials for user data. • Missing scope grants. • Long-lived secrets. • Not validating audience. • Guessing instead of decoding tokens.

Conceptual study map, not an SAP configuration screenshot or a guaranteed runtime sequence. Consult the lesson for implementation prerequisites and exceptions.

Code example

ABAP Code
===== PROVIDER (app B) xs-security.json excerpt ===== (grant-as-authority-to-apps pre-grants this scope to app A, so app A doesn't need a user to manually assign it; the excerpt stays plain JSON, comments go outside it)"scopes": [ { "name": "$XSAPPNAME.Read", "grant-as-authority-to-apps": ["$XSAPPNAME(application,orders-a)"] } ] ===== CONSUMER (app A) ===== (declares it will use the scope granted by app B, qualified with app B's XSAPPNAME)"authorities": ["$XSAPPNAME(application,orders-b).Read"] ===== FLOWS =====Client credentials: POST /oauth/token grant_type=client_credentials  # service-to-service call with no end user involved, authenticating as the app's own client id/secretJWT bearer (user): grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer with user's token  # exchanges the calling user's existing token for a new one scoped to the target app, preserving the user's identity

Watch out

Common mistakes

  • Client credentials for user data.
  • Missing scope grants.
  • Long-lived secrets.
  • Not validating audience.
  • Guessing instead of decoding tokens.

Do this

Best practices

  • Choose flow by user need.
  • Explicit grants.
  • Certificates or rotation.
  • Validate issuer/audience.
  • Decode tokens when debugging.

In the interview

Interview angle

Questions: "Client credentials vs token exchange?", "How does one app grant scopes to another?", "How do you troubleshoot 403?"
Strong answer: flows, grants, credential types, troubleshooting.

Practice this lesson

Quick check

0 of 3 questions attempted

Question 1 of 3

In the Kyma environment, how is application-level authentication and authorization typically enforced for microservices instead of relying solely on native XSUAA integration within the application code?

Practise this in an interview

Answer in your own words and get instant feedback, the way an interviewer would judge it.

1A service calls another API and users see data they shouldn't. How do you design app-to-app security?

2A production issue is reported in BTP Security for Integration and Application Architecture. What would you check first, and how would you troubleshoot it systematically?

See it in code

Each example starts from a requirement, shows the design, then the code step by step with a plain-language explanation of every part.

Was this lesson helpful?

Keep exploring

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.