Skip to Content
Technical Articles

Authentication using XSUAA | Migrating from the Neo Environment to the Multi-Cloud Foundation

This blog post series is about developing applications in a multi-cloud environment.

For the end-to-end hands-on tutorial example, see

For the step-by-step series, visit

  1. Cloud Foundry, UAA, and XSUAA
  2. Business Logic App
  3. Service Instance (SAP HANA Cloud)
  4. Application Router
  5. Authentication using XSUAA <<< this post
  6. Authorization using XSUAA
  7. Multi-target applications (MTA)
  8. Application Runtime (Appendix)

Questions? Post as comment.

Useful? Give us a like and share on social media.



Hands-On Tutorials

Developing Secure Applications on the SAP Cloud Platform

In this blog series, we explore authentication and authorisation using XSUAA in the SAP Cloud Platform, Cloud Foundry environment.

In this blog, we cover how we can authenticate access to our business logic app.

Tutorial Video

In this sixth video of the series, we explore authentication using XSUAA service with some code changes to the business logic of our services app.

Sample Code

As before, we continue with the (slightly modified) sample code from SAP Cloud Platform documentation:

You can download the sample code from repository


For more detailed information about the SAP Cloud Platform trial environment, Cloud Foundry buildpacks, dependencies declarations, attributes, Diego cells and more, see the “appendix” blog


Business Logic App

Application Descriptor | Package.json

For authorisation, we are going to use passport, a generic Node.js module, together with the XS Advanced Container Security API for Node.js.

Passport is Express-compatible authentication middleware for Node.js (as documented) and we use xsenv to read the application configurations for bound services and certificates in the SAP Cloud Platform Cloud Foundry environment, and xssec for the security configuration.

As documented

To make a connection to SAP HANA Cloud, we use the HDB (SAP HANA) convenience package with xsenv to lookup the bound hana service for credentials.

npm i passport
npm i @sap/xssec
npm i @sap/xsenv

This results in the following dependencies for our package.json file.

"dependencies": {
    "@sap/xsenv": "^3.0.0",
    "@sap/xssec": "^3.0.10",
    "passport": "^0.4.1"

Business Logic | Server.js

To the business logic, we change the getServices call to both the hdicontainer-1 service and myxsuaa services created previously.

We initialise password with JWT authentication using xssec. This is boilerplate code from

The /xsuaa path returns the authenticated user id (platform) and the user from the hana environment.

const xsenv = require('@sap/xsenv');
var services = xsenv.getServices({ hana:'hdicontainer-1', uaa:'myxsuaa' });

const passport = require('passport');
var JWTStrategy = require('@sap/xssec').JWTStrategy;
passport.use(new JWTStrategy(services.uaa));
app.use(passport.authenticate('JWT', { session: false }));

// Get environment using passport, xsenv, and xssec
app.get('/xsuaa', function (req, res, next) {
  res.send('Application user: ' + + '<br>' + 'HANA user: ' + services.hana.user);


Application Router

We continue with the approuter as configured in the previous blog where we installed the @sap/approuter package and defined the route(s) in the xs-app.json file.

User Interface | Index.html

To the home page of the approuter add a line to point to /xsuaa.

  <title>XSUAA Tutorial</title>
  <h1>XSUAA Tutorial</h1>
  <a href="/myapp/"> get('/')</a></br>
  <a href="/myapp/xsuaa">get('/xsuaa'</a></br>
  <a href="/myapp/hana">get('/hana')</a>

App Router Description | xs-app.json


The router will forward any request to /myapp to the destination with name “myapp” (no changes).

This destination is defined in the manifest (no changes).


App Deployment

Command Line

To deploy the app run the cf push command. No changes were made to the manifest.

# housekeeping
cf d[elete] myapp -r -f
# deploying
cf push
# running
cf a[pps]


When we now access the business logic app directly we get an HTTP 403 Unauthorized message.

App Router

When we access the app router, we are first prompted to provide the credentials to our identity provider, here SAP ID services.

We are then presented with the home page (index.html) of the Application Router.

Selecting the links makes a call the business logic app. Note that we remain connected to the Application Router.


Please Proceed

In the next blog we explain how we can configure our app for authorization.


Share and Connect

Questions? Post as comment.

Useful? Give a like and share on social media. Thanks!

If you would like to receive updates, connect with me on


Denys van Kempen



You must be Logged on to comment or reply to a post.
  • Hey Denys van Kempen ,


    thanks for the great blogs, I really like it.

    My manifest file and xs-app.json file looks like:

    - name: myapp2
      path: .
      - route:
      - python_buildpack
      command: python app/
      memory: 128MB
      disk_quota: 512MB
        - myuaa
    - name: approuter2
      path: approuter
      - nodejs_buildpack
      memory: 128MB
      disk_quota: 512MB
        destinations: >
              "forwardAuthToken": true
        - myuaa
      "routes": [
          "source": "^/myapp/(.*)$",
          "target": "$1",
          "destination": "dest"


    When I push my code to cf everything will be successfully created, but when I access my business application directly, than I will not receive an "unauthorized" message, it is started. Even when I access the approuter URL I will be redirected for login (XSUAA) this is fine. But why I am able to open the business application directly, did I forget something in the config?

    Another question is, how is it also possible to redirect after success Login to my business application, instead of approuter index.html ?

    Thanks and best regards,


    • Hi Hasan,

      When you bind an application to the XSUAA service, its configuration (scopes, roles) will be applied. Ideally, the microservices should not be directly accessible (e.g. have a public route)

      You can configure the router anyway you want. Below a sample that forwards all requests to the srv destination (defined in the manfiest).

        "authenticationMethod": "route",
        "routes": [
                "source": "/(.*)",
                "authenticationType": "xsuaa",
                "scope": "uaa.user",
                "destination": "srv"


  • Hi Denys,

    thank you very much for this great block. Helps me enough 🙂

    I will try to ask you the following question, because I couldn't find any solution 🙁

    We just implemented HTML5 applications in BTP Cloud Foundry as a Multitarget application and with XSUAA enabled.
    We also deployed the application with the "Managed Application Router" option, as it's recommended by SAP.
    Now we want to activate Authentication and Authorization for the application but couldn't find any solution.
    We found the following documentation, but it seems it's only working for usage with own application router.

    So the question is how it's possible to secure a html5 app with a managed application router ?

    Best regards,

    • Hi Andreas,

      Thanks; good to hear the post has been useful.

      Would you mind posting the question to (copy/paste is fine); Maybe add a print screen of the issue with the relevant code.

      Tag with SAP BTP Cloud Foundry, SAP Security, XSUAA

      The forum is monitored by experts from the community which benefits a timely response and also allows for knowledge sharing. Others might face the same issue.