title: Get user info from ui5 app within Cloud Foundry's Fiori Launchpad
body: <p>As the title says, I'm trying to retrieve user info from an application which is in the Cloud Foundry's FLP.</p>
  
  <p>I've followed the following blog:
  <a href="https://blogs.sap.com/2019/05/23/how-to-get-the-email-of-the-logged-in-user-in-cloud-foundry/" rel="nofollow noreferrer">https://blogs.sap.com/2019/05/23/how-to-get-the-email-of-the-logged-in-user-in-cloud-foundry/</a></p>
  
  <p>However my application structure is different and I don't know how to make it work.</p>
  
  <p>First, I can sum up the project creation to these two links:</p>
  
  <ol>
  <li><a href="https://developers.sap.com/tutorials/cp-ui5-webide-new-app.html" rel="nofollow noreferrer">https://developers.sap.com/tutorials/cp-ui5-webide-new-app.html</a></li>
  <li><a href="https://developers.sap.com/tutorials/cp-portal-cloud-foundry-create-launchpad.html" rel="nofollow noreferrer">https://developers.sap.com/tutorials/cp-portal-cloud-foundry-create-launchpad.html</a></li>
  </ol>
  
  <p>Here's my application's structure:</p>
  
  <p><a href="https://i.stack.imgur.com/L8FTH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L8FTH.png" alt="enter image description here"></a></p>
  
  <p>With the associated mta.yaml:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>ID: mta_ztransport_appointment
  _schema-version: '2.1'
  parameters:
    deploy_mode: html5-repo
  version: 0.0.1
  modules:
    - name: mta-ztransport-appointment-approuter
      type: approuter.nodejs
      path: mta-ztransport-appointment-approuter
      parameters:
        disk-quota: 256M
        memory: 128M
      requires:
        - name: mta_ztransport_appointment_html5_repo_runtime
        - name: uaa_mta_ztransport_appointment
        - name: portal_resources_mta_ztransport_appointment
        - name: dest_mta_ztransport_appointment
        - name: conn_mta_ztransport_appointment
    - name: mta_ztransport_appointment_ui_deployer
      type: com.sap.html5.application-content
      path: mta_ztransport_appointment_ui_deployer
      requires:
        - name: mta_ztransport_appointment_html5_repo_host
      build-parameters:
        requires:
          - name: ztransport.appointment
            artifacts:
              - './*'
            target-path: resources/ztransport.appointment
    - name: ztransport.appointment
      type: html5
      path: ztransport.appointment
      build-parameters:
        builder: custom
        commands:
          - npm install
          - npm run build
        supported-platforms: []
        build-result: dist
    - name: flp
      type: com.sap.portal.content
      path: flp
      parameters:
        stack: cflinuxfs3
        memory: 128M
        buildpack: 'https://github.com/cloudfoundry/nodejs-buildpack/releases/download/v1.6.39/nodejs-buildpack-cflinuxfs3-v1.6.39.zip'
      requires:
        - name: portal_resources_mta_ztransport_appointment
        - name: uaa_mta_ztransport_appointment
        - name: mta_ztransport_appointment_html5_repo_host
        - name: mta_ztransport_appointment_ui_deployer
  
    
  
  resources:
    - name: mta_ztransport_appointment_html5_repo_runtime
      parameters:
        service-plan: app-runtime
        service: html5-apps-repo
      type: org.cloudfoundry.managed-service
    - name: mta_ztransport_appointment_html5_repo_host
      parameters:
        service-plan: app-host
        service: html5-apps-repo
      type: org.cloudfoundry.managed-service
    - name: uaa_mta_ztransport_appointment
      parameters:
        path: ./xs-security.json
        service-plan: application
        service: xsuaa
      type: org.cloudfoundry.managed-service
    - name: dest_mta_ztransport_appointment
      parameters:
        service-plan: lite
        service: destination
      type: org.cloudfoundry.managed-service
    - name: portal_resources_mta_ztransport_appointment
      parameters:
        service-plan: standard
        service: portal
      type: org.cloudfoundry.managed-service
    - name: conn_mta_ztransport_appointment
      parameters:
        service-plan: lite
        service: connectivity
      type: org.cloudfoundry.managed-service</code></pre>
  </div>
  </div>
  </p>
  
  <p>The xs-security.json file:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>{
   "xsappname": "mta_ztransport_appointment",
   "tenant-mode": "dedicated",
   "description": "Security profile of called application",
   "scopes": [{
    "name": "$XSAPPNAME.Display",
    "description": "display"
   }, {
    "name": "$XSAPPNAME.Update",
    "description": "update"
   }, {
    "name": "uaa.user",
    "description": "UAA"
   }],
   "role-templates": [{
    "name": "Token_Exchange",
    "description": "UAA",
    "scope-references": [
     "uaa.user"
    ]
   }, {
    "name": "Viewer",
    "description": "View Users",
    "scope-references": [
     "$XSAPPNAME.Display"
    ]
   }, {
    "name": "Manager",
    "description": "Maintain Users",
    "scope-references": [
     "$XSAPPNAME.Display",
     "$XSAPPNAME.Update"
    ]
   }]
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>The xs-app.json in approuter folder:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>{
    "welcomeFile": "/cp.portal",
    "authenticationMethod": "route",
    "logout": {
      "logoutEndpoint": "/do/logout"
    },
    "routes": [
      {
        "source": "^/Dirickx_DE1/(.*)$",
        "target": "$1",
        "authenticationType": "none",
        "destination": "Dirickx_DE1",
        "csrfProtection": false
      },
      {
        "source": "^(.*)$",
        "target": "$1",
        "service": "html5-apps-repo-rt",
        "authenticationType": "xsuaa"
      }
    ]
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Quite the same approuter-start.js than the blog put in the approuter folder.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>var approuter = require('@sap/approuter');
  var ar = approuter();
  ar.beforeRequestHandler.use('/getuserinfo', function (req, res, next) {
   if (!req.user) {
    res.statusCode = 403;
    res.end("Missing JWT Token");
   } else {
    res.statusCode = 200;
    res.end("My name is ${JSON.stringify(req.user.name, null, 2)}");
   }
  });
  ar.start();</code></pre>
  </div>
  </div>
  </p>
  
  <p>And package.json in approuter folder as follows:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>{
   "name": "html5-apps-approuter",
   "description": "Node.js based application router service for html5-apps",
   "engines": {
    "node": "^8.0.0 || ^10.0.0"
   },
   "dependencies": {
    "@sap/approuter": "6.8.0"
   },
   "scripts": {
    "start": "node ./approuter-start.js"
   }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>My xs-app.json file is different from the one from the blog and I think the error comes from it but if I stick to the blog, the deployment fails.
  And with the one I'm using, the deployment works but the request isn't made.</p>
  
  <p>Any idea?
  Thanks</p>