Skip to Content
Technical Articles
Author's profile photo Milton Chandradas

How to get logged in user in SAP Cloud Platform (Cloud Foundry)

Github repository:

https://github.com/miltonchandradas/loggedinuserCF (Branch: part2)

 

Introduction:

  • In this session, we will look at how to get the logged in user in SAP Cloud Platform (Cloud Foundry environment)

 

Synopsis:

  • SAP Cloud Platform can be set up with any Identity Provider that supports SAML
  • When building SAPUI5 applications, we can require that users be authenticated against this Identity Provider
  • There may be many instances where you might want to display user specific messages on the home page (for example, some form of welcome message) – and for this you need to know the logged in user
  • In Cloud Foundry, the user authentication is handled by the approuter which performs all the complex OAuth flows

 

Steps:

  • Unlike the Neo environment, there is no ready made userapi service provided by SAP Cloud Platform Cloud Foundry that provides the logged in user information
  • However, the Cloud Foundry provides us with the approuter that performs all the complex OAuth flows
  • We can add custom middleware functions that can query the request object and extract the user information inside of it
  • The user information itself is stored in a JWT Token that can be retrieved and decoded using a npm package (in our case, we are using jwt-decode)
  • Please note that we are not validating the JWT Token, but merely decoding it and getting the user information in the payload of the JWT Token
  • Check out https://jwt.io/ for more information on JWT Tokens

 

YouTube link:

 

Conclusion:

  • This video should give you a clear idea on how to get the logged in user in SAP Cloud Platform Cloud Foundry environment
  • You should also have a good handle on how middleware functions work and how the JWT Tokens are used in the OAuth flows
  • If you have any questions or comments, please list them below and I will be happy to answer

 

Previous post:

https://blogs.sap.com/2020/08/23/how-to-consume-destinations-in-sap-cloud-platform-cloud-foundry/

 

Next post:

 

Related post:

https://blogs.sap.com/2020/08/23/how-to-get-logged-in-user-in-sap-cloud-platform-neo-environment/

 

Assigned tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Kamalpreet Kaur
      Kamalpreet Kaur

      Hi Milton Chandradas,

      Can you provide any reference how do we fetch logged in user details in case of managed approuter.

      Thanks,

      Kamalpreet Kaur

      Author's profile photo parthibaraja vijayan
      parthibaraja vijayan

      Hi Milton,

      Great blog. Any idea on how to achieve this in a CAP application with managed approuter.

       

      Regards,

      Parthi