Skip to Content

Using CAP model: Retrieve logged-in user details in Cloud Foundry Using Web IDE

Hello All,

We are trying to retrieve the logged-in user details using SAP Cloud platform business application in WEBIDE.

We have followed the below blog to retrieve the logged-in user details in MTA project:

https://blogs.sap.com/2020/06/04/retrieve-logged-in-user-details-in-cloud-foundry-using-web-ide/

It is working fine with MTA project, but we are unable to replicate the same in Cloud platform business application project.

Is there any way to get the logged-in user details in the CDS level or in the .js file of SRV module?

Thanks and Regards,

Vivek Babu

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Jul 06 at 10:02 AM

    Hi,

    where do you want to use the information of the registered user? Do you need them within a UI5 app or in the CAP backend within the handlers?

    What do you mean with "but we are unable to replicate the same in Cloud platform business application project"?

    If you need the information in the CAP handlers, you can either use the object req.user or decode the JWT. For this the SAP Cloud Sdk offers a good method.

    If you need the information in a UI5 app, simply implement an e.g. REST endpoint that provides you with the information, either from the req.user object again or by decoding the JWT.

    See also:

    https://blogs.sap.com/2020/04/06/show-current-user-details-in-cloud-foundry-apps-with-ias/ (Solution 3)

    Regards
    Simon

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 06 at 04:36 AM

    On the services level there exists the req.user object which contains information about the logged in user (if an UAA instance is used).

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.