简体   繁体   English

从 Cloud Foundry 的 Fiori Launchpad 中的 ui5 应用程序获取用户信息

[英]Get user info from ui5 app within Cloud Foundry's Fiori Launchpad

As the title says, I'm trying to retrieve user info from an application which is in the Cloud Foundry's FLP.正如标题所说,我正在尝试从 Cloud Foundry 的 FLP 中的应用程序中检索用户信息。

I've followed the following blog: https://blogs.sap.com/2019/05/23/how-to-get-the-email-of-the-logged-in-user-in-cloud-foundry/我关注了以下博客: https://blogs.sap.com/2019/05/23/how-to-get-the-email-of-the-logged-in-user-in-cloud-foundry/

However my application structure is different and I don't know how to make it work.但是我的应用程序结构不同,我不知道如何使它工作。

First, I can sum up the project creation to these two links:首先,我可以将项目创建总结为这两个环节:

  1. https://developers.sap.com/tutorials/cp-ui5-webide-new-app.html https://developers.sap.com/tutorials/cp-ui5-webide-new-app.html
  2. https://developers.sap.com/tutorials/cp-portal-cloud-foundry-create-launchpad.html https://developers.sap.com/tutorials/cp-portal-cloud-foundry-create-launchpad.html

Here's my application's structure:这是我的应用程序的结构:

在此处输入图像描述

With the associated mta.yaml:使用关联的 mta.yaml:

 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

The xs-security.json file: xs-security.json 文件:

 { "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" ] }] }

The xs-app.json in approuter folder: approuter 文件夹中的 xs-app.json:

 { "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" } ] }

Quite the same approuter-start.js than the blog put in the approuter folder.与放在 approuter 文件夹中的博客完全一样的 approuter-start.js。

 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();

And package.json in approuter folder as follows: approuter文件夹中的package.json如下:

 { "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" } }

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.我的 xs-app.json 文件与博客中的文件不同,我认为错误来自它,但如果我坚持博客,部署将失败。 And with the one I'm using, the deployment works but the request isn't made.使用我正在使用的那个,部署工作但没有提出请求。

Any idea?任何想法? Thanks谢谢

The blog you mentioned creates a specific route in the approuter /getuserinfo so that when you deploy the approuter and go to https://<app_router_domain_from_SCP>.hana.ondemand.com/getuserinfo it decodes the JWT token you've got from logging in and returns the details. The blog you mentioned creates a specific route in the approuter /getuserinfo so that when you deploy the approuter and go to https://<app_router_domain_from_SCP>.hana.ondemand.com/getuserinfo it decodes the JWT token you've got from logging in并返回详细信息。

You need to make the request yourself to get the data.您需要自己提出请求以获取数据。

If you want to use the data in a UI5 app, I would just make the /getuserinfo handler return the data in JSON format and use a JSONModel on that URL.如果您想在 UI5 应用程序中使用数据,我只需让/getuserinfo处理程序以 JSON 格式返回数据,并在该 URL 上使用 JSONModel。 You can then bind to the new model as you would any other model.然后,您可以像绑定任何其他 model 一样绑定到新的 model。

Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM