cancel
Showing results for 
Search instead for 
Did you mean: 

How to get logged in user in UI5 application deployed in Cloud Foundry

0 Kudos

Hi,

How to get the current logged in user information in sap UI5 deployed in CF?

please help if you know the answer.

Thanks in advance.

0 Kudos

Hello All,

Is there any one who followed the below link to get the information of 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/

https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/4902b6e66cbd42648b5d9eaddc6...

It is an Multi Target Application (MTA) having modules Node Js, UI5, Hana DB and XSJS.

I just need a reference of Authentication for Node Js application.

Thanks & Regards,

Poorvi

0 Kudos

Hi Poorvi,

I am facing the same problem as yours. By any chance are you able to get logged in User with node.js app?

Accepted Solutions (0)

Answers (4)

Answers (4)

mariusobert
Developer Advocate
Developer Advocate

I'm not aware that there is a direct way to read the information from the UI5 app.

What you can do, is write a simple server app (or even a FaaS) that reads the JWT token from the request, and returns the information you would like to read. Then, you could call this endpoint from the app.

Here's an example in Java, but it obviously works with nodejs as well.

Please keep in mind: JWT tokens should remain a secret to the user. Do not forward the entire token!

0 Kudos

Hi Marius Obert,

Thanks for the information.

I am trying to follow this link :- https://blogs.sap.com/2019/05/23/how-to-get-the-email-of-the-logged-in-user-in-cloud-foundry/

If you have any info on above link please let me know.

Thanks,

Poorvi

nabheetscn
Active Contributor

Hi poorvi jain

Did you try out the mentioned approach if yes any issue you faced?

Thanks

Nabheet

0 Kudos

Hi Nabheet Madan,

I tried the above approach but the proper path is not given in link like where to create these files the proper path to create a file. approuter-start.js and manifest.yml file.

Thanks,

Poorvi

mariusobert
Developer Advocate
Developer Advocate
0 Kudos

I'd recommend creating a new folder for this to get started. All the mentioned files should be in this new folder. You can then copy your UI5 project (or any webapp) to a new "resources" folder in this project.

Once you are familiar with this approach, you can refactor the code if needed.

0 Kudos

Hi Marius Obert,

I just created a sample MTA project and have added a HTML5 module and inside a HTML5 module added a approuter file now I am trying to call this approuter-start.js file from package.json file but I can see in network tab the approuter-start.js file is not getting called.

I just wants to call this approuter-start.js file from package.json file.

approuter-start.jpg packagejson-file.jpg

Thanks & Regards,

Poorvi

mariusobert
Developer Advocate
Developer Advocate
0 Kudos

Your code looks correct. Maybe I misunderstood you but I sounded like your app router would be inside the HTML module. In case that right, that explains why it's not being called. The html5 module is most likely the approuter that is serving the UI files. Here is an example that shows an approuter that contains a web app.

If you move your code on this level, it should work.

abdel_dadouche
Active Contributor

Hi,

I recently implemented the XSUAA API based on thomas.jung blog post (https://blogs.sap.com/2018/04/23/sap-hana-xsa-controller-api-interaction/) which provided me access to most user login details (in addition to roles etc).

It requires to create a node.js module to be deployed and used by your sapui5 application.

You can check the associated GitHub repo: https://github.com/jungsap/controllerAPI.

Hope this helps.

0 Kudos

Hi,

Did you get the correct answer? I have been able to extract the email information of the logged in user but I also need the I-number of the logged in user. If you were able to get that information in CF please let me know.

0 Kudos

Hi shivam25,

Are you able to extract the email information of the logged in user in cloud foundry?

If you are then please let me know how to get the info.

Thanks & Regards,

Poorvi

0 Kudos

Hi Poorvi,

I was able to fetch the information by using the JWT token forwarded to the backend. To fetch the information in the UI you can follow the below mentioned link and you'll get basic email information.

https://blogs.sap.com/2019/05/23/how-to-get-the-email-of-the-logged-in-user-in-cloud-foundry/

0 Kudos

Hi Shivam Aggarwal,

I followed this link that you have shared but the problem is I don't know where to create this approuter-start.js and manifest.json file.

Can you please share some reference project so that i can have a better understanding.

Thanks & Regards,

Poorvi

0 Kudos

Hi Poorvi,

You can view the below mentioned project as a sample project for directory structure you might need. The path of approuter to be used is given in package.json of the project you can change that and create the new approuter-start.js as required. approuter-start.js will add this getuserinfo endpoint and keep rest of the functionalities to the default approuter.js provided within the node_modules.

https://github.com/boudhayan-dev/spring-xsuaa-cloud-foundry

0 Kudos

Hi Shivam Aggarwal,

I followed this link https://blogs.sap.com/2019/05/23/how-to-get-the-email-of-the-logged-in-user-in-cloud-foundry/

I am getting this error "/home/vcap/app/node_modules/@sap/approuter/lib/environment.js:19 throw new Error('File not found ' + xsappFile); ^ Error: File not found /home/vcap/app/xs-app.json at Object.getWorkingDirectory (/home/vcap/app/node_modules/@sap/approuter/lib/environment.js:19:13) at Object.module.exports.load (/home/vcap/app/node_modules/@sap/approuter/lib/configuration.js:13:32) at bootstrap (/home/vcap/app/node_modules/@sap/approuter/lib/bootstrap.js:52:36) at Approuter.start (/home/vcap/app/node_modules/@sap/approuter/approuter.js:67:13) at Object.<anonymous> (/home/vcap/app/server.js:45:4) at Module._compile (module.js:653:30) at Object.Module._extensions..js (module.js:664:10) at Module.load (module.js:566:32) at tryModuleLoad (module.js:506:12) at Function.Module._load (module.js:498:3) npm ERR! code ELIFECYCLE npm ERR! errno 1"

Do you have any idea about this error in node js.

my application is a multi target application.

Thanks & Regards,

Poorvi

0 Kudos

Hi Poorvi,

If you check the github link I attached previously in the comment, you'll see a xs-app.json file being created in the approuter folder of the project. You'll need to create the same file. You can refer to that link to see the right project structure.

0 Kudos

Hi shivam25,

I just created a sample MTA project and here I have created a HTML module and added a approuter file in the same HTML module now I am trying to call this approuter-start.js file from package.json file but I can see in network tab the approuter-start.js file is not getting called.

you have provided me java based solution but I need Node js project for reference.

approuter-start.jpg

packagejson-file.jpg

Thanks & Regards,

Poorvi

former_member540067
Active Participant
0 Kudos

Hi poorvijain08 .

You can use the USER API provided by SAP. Please follow the below link.

https://bit.ly/38QapqQ

Regards

Anmol

0 Kudos

Hi Anmol Chadha,

Thanks for the answer.

But my application is deployed in Cloud foundry.

It's configuration for NEO environment... it is working for NEO not for CF.

Thanks,

Poorvi

former_member540067
Active Participant
0 Kudos

Oh my Bad!!.

Sorry for that. No ideas for cloud foundry.!