In this lesson we will look at the Authentication steps involved in Application Security.
The following diagram shows the architecture with the components that are responsible for business user authentication, authorization management, and security.

Approuter
Approuter – is Node JS library that is available in Public NPM. It represents a single entry point to your application.
Its tasks are:
- The Approuter dispatches requests to our back end microservices, thus acting as a reverse proxy. The back end microservices should not be directly accessible by the client.
- The Approuter can serve static content such as web pages, SAPUI5, or another client-side code.
- The Approuter manages the authentication flows for our entire application.
For authentication (who the user is) and authorization (what the user is allowed to do), the App Router takes all incoming, unauthenticated request and initiates an OAuth2 flow (authorization code grant) with the Extended Services for User Account and Authentication (XSUAA) service of the SAP BTP in the Cloud Foundry environment .
Main Properties on root level
- authenticationMethod
This property indicates which authentication will be applied for this xs-app.json. Can be none (means that all routes are not protected) and route (authentication type will be chosen according to definition in a particular route). The default value is route .
- logout
By using this property, you can define two important thing about your business application central logout handling.
logoutEndpoint – contains some internal path. When accessing this path your application will trigger central logout procedure. Triggering central logout will destroy user session data in Approuter, call XSUAA in order to remove user session on their side and also will call logout paths of destinations that are defined for this specific application (please refer to property destinations).
logoutpage – can be internal path or absolute external URL. Value of this field describes so called "landing page" page address, that user will be redirected in the browser after central logout.
- destinations
This property indicates destinations endpoints that need to be called during session/central logout in order to destroy sessions on their side.
- services
The same as destinations. Services can implement their specific logout logic and approuter will trigger these endpoints during central logout / session timeout scenario.
Routing
One of important capabilities of AppRouter is to be a reverse proxy for your application. In order to achieve that you need to model correctly property routes. That property is an array of Objects. Each object represents one particular route.
Install via Service Marketplace
The App Router is a Node.js component, distributed via the publicly available SAP NPM registry
The Application Router's Design-Time Descriptor: xs-app.json
The SAP Authorization and Trust Management service lets you manage user authorizations and trust to identity providers. Identity providers are the user base for applications. You can use an identity authentication tenant, an SAP on-premise system, or a custom corporate identity provider. User authorizations are managed using technical roles at the application level, which can be aggregated into business-level groups and role collections for large-scale cloud scenarios.
You can set up and run your own application router or you can use the application router that is managed by SAP (for more information see Managed Application Router).
SAP recommends running your standalone app router only in advanced cases, for example when application router extensibility is required
The managed application router enables you to access and run HTML5 applications in a cloud environment without the need to maintain your own runtime infrastructure.
The managed application router is the HTML5 applications runtime capability that is provided by the following products:
SAP Work Zone
SAP Launchpad service
SAP Cloud Portal
To use the managed application router, you must be subscribed to one of these services.
OAuthCloud Foundry Applications use OAuth 2.0, When business users access an application, the application router acts as OAuth client and redirects their request to the OAuth authorization server for authentication. Runtime containers act as resource servers, using the container security API of the relevant container (for example, Java, Nodejs) to validate the token issued by the OAuth authorization server.
JSON Web Token (JWT)A JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self\u0002contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA or ECDSA.
Although JWTs can be encrypted to also provide secrecy between parties, we will focus on signed tokens. Signed tokens can verify the integrity of the claims contained within it, while encrypted tokens hide those claims from other parties. When tokens are signed using public/private key pairs, the signature also certifies that only the party holding the private key is the one that signed it.
When should you use JSON Web Tokens?
Here are some scenarios where JSON Web Tokens are useful:
Authorization
This is the most common scenario for using JWT. Once the user is logged in, each subsequent request will include the JWT, allowing the user to access routes, services, and resources that are permitted with that token. Single Sign On is a feature that widely
uses JWT nowadays, because of its small overhead and its ability to be easily used across different domains.
Information Exchange
JSON Web Tokens are a good way of securely transmitting information between parties. Because JWTs can be signed-for example, using public/private key pairs-you can be sure the senders are who they say they are. Additionally, as the signature is calculated using
the header and the payload, you can also verify that the content hasn't been tampered with.
Extended Services - User Account and Authentication (XSUAA) service
The Extended Services - User Account and Authentication (XSUAA) service is one of the most important components to deal with when developing your own applications on Cloud Foundry. It takes care to authenticate and authorize your users and assign the right principals to your user’s session so your application can:
Identify the user by Email, UserId, First and Lastname
Check its roles (scopes) to decide if a user is allowed to do something or prohibit its action
The XSUAA is an internal development of SAP. SAP took the base of the open source UAA OAuth2 Provider of Cloud Foundry and extended it with SAP specific features to be used in SAP applications. One important thing is that the XSUAA does NOT store "real" users. This is why the XSUAA needs to trust an external Identity Provider (IdP).

In Feature Set B, your SAP BTP global account has its own XSUAA tenant. This XSUAA tenant by default has a trust relationship to the SAP ID Service. The SAP ID Service manages a large base of users, that have created a user account with SAP. You can add users, that exist in the SAP ID Service, as members to your global and subaccount. In order for these users to be able to perform administrative tasks, they need to be assigned with corresponding role-collections. There is a set of default platform role-collections, like Global Account Administrator, Global Account Viewer, Subaccount Administrator or Cloud Connector Administrator that you can use for the purpose of assigning SAP BTP account management authorizations.
Contrary to the platform users from the SAP ID Service, your business users can also be provided via your own corporate identity provider. These are the users you want to provide access to your business applications. These might be SaaS applications provided by SAP, like SAP Business Application Studio or SAP Workflow Management, or your own applications that you develop on the SAP BTP. The business applications have their own role-collections, like e.g. Business_Application_Studio_Developer, WorkflowManagementAdmin, or any custom role-collection that you create for your application. It is planned by the end of 2021 to also support corporate identity providers for platform users.
Role-Collections, Roles and Scopes
The following image shows the relationships between role-collections, roles and scopes.

Scopes
Scopes are arbitrary values that express authorizations / access rights in an application or service. Scopes need to be prefixed with an xsappname to make them uniquely identifiable.
Roles
Roles are entities that hold several scopes. Scopes can be put in multiple roles, so you are not limited to have scopes sitting in just one role.
Role-Collections
Role-collections contain one or more roles. A role can be used in multiple role-collections. But it is totally fine to have for example a role-collection called Admin that only has an admin role.
Role-collections are stored as an assignment in the XSUAA and are THE entity that can be assigned to a certain business user.
How does it work in practice?
Watch this video to learn more about the scope, role-collections, and roles. In this video, you can see that there are different personas. One is the developer working within a project and space. The other persona is an admin taking care of the CF account as a security admin.
What is a xs-security.json? To simplify things, let’s just call the xs-security.json the "declaration of your app’s security".
The following xs-security.json is an excerpt of the office supplies application being built in our example.
{
"xsappname": "HC_OFF_SUPPLIES",
"tenant-mode": "dedicated",
"scopes": [
{
"name": "$XSAPPNAME.Vendor",
"description": "Supplier"
},
{
"name": "$XSAPPNAME.ProcurementManager",
"description": "Manager"
}
],
"attributes": [],
"role-templates": [
{
"name": "Vendor",
"description": "Supplier",
"scope-references": [
"$XSAPPNAME.Vendor"
],
"attribute-references": []
},
{
"name": "ProcurementManager",
"description": "Manager",
"scope-references": [
"$XSAPPNAME.ProcurementManager"
],
"attribute-references": []
}
]
}
You have to tell the XSUAA service how to call your application (xsappname
) and further define your scopes and role-templates. The scopes are being used within the application to check concrete permissions whenever a user tries to perform a certain action.