Skip to Content
Author's profile photo Jamie Cawley

Using the SAP Cloud Platform UserAPI in Mobile Services Development & Operations

Overview

The SAP Cloud Platform UserAPI provides a service which can be used to access details of the logged in user.  The details of this service can be found at

https://help.hana.ondemand.com/help/frameset.htm?1de599bf722446849d2b2e10132df42a.html

This service is available to html5 applications running on the Cloud Platform.  For an example of utilizing it in a html5 application see

Using the SAP HCP User API in SAP Web IDE

To utilize this service in a Mobile Services application we can perform the following

STEP 1: Create HTML5 App

To utilize this service in Mobile Services we first need to create an html5 app that exposes access to the service.  The only requirement for this app is to have a route defined in it’s neo-app.json for the userapi service.  You can either follow the above mentioned blog, add to any existing app running on the Cloud Platform or create a new UI5 app in Web IDE and add the following entry in the neo-app.json

{ 
  "path": "/services/userapi", 
    "target": { 
       "type": "service", 
       "name": "userapi" 
    } 
}

After making the change deploy the app to the Cloud Platform.  This can be done in Web IDE by right clicking on the app and choosing Deploy -> Deploy to SAP Cloud Platform.  In my case I have provided the app name userapi.

STEP 2: Add connection in Mobile Services Development & Operations

In Mobile Service for Development and Operations choose the menu option Connections.  Add a new connection that points to your app with /services/userapi appended to the url as shown

Set the SSO Mechanism to Application To Application SSO

Add this connection to the desired application by choosing the tab Back End of the desired application and adding the connection to the Application Connections section

STEP 3: Finalize/Test Mobile Services Application

This scenario requires that you are using SAML authentication for the Mobile Services application.  This can be done by setting the Security Configuration property, found under the Information tab, of the app to Form.  For more information regarding the use of SAML with Kapsel application see

https://blogs.sap.com/2017/02/02/appendix-d-saml/

You should now be able to use this connection within your Kapsel app.  An example of accessing the CurrentUser would be as follows.

https://hcpms-XXXXXtrial.hanatrial.ondemand.com/userapi/currentUser

Assigned Tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hey Jamie,

      We have a unique workflow.  One where we use an edmx file from our real on-premise ODATA in WebIDE in order to build the application.  Once finished, we import the archive into our local machines and aim to change the application to the ODATA backend in Java EE.

      My question is how does one feed this WebIDE derived applications the serviceURL?  It seems there is no guide for this in specific.  I was hoping you could shed some light on it.

      As you know some clients just won't allow cloud connector or WebIDE local Installation. Thank you.

      Author's profile photo Jamie Cawley
      Jamie Cawley
      Blog Post Author

      Hi Shashank,

      Can you please create a new post in the Questions and Answers marked with the appropriates tags for you inquiry?

      Regards,

      Jamie

      Author's profile photo Former Member
      Former Member

      https://answers.sap.com/questions/172763/index.html

      I already have sir.  Thank you for your response. We really require a solution.

      Author's profile photo Luca Motta
      Luca Motta

      Hi Jamie,

      I’m working with a NO-trial HCPMS. My back-end url is https://xxx-xxxxxxxxx.dispatcher.hana.ondemand.com/services/userapi. This URL from chrome works.

      On HCPMS destination creation wizard on SAML2 Audience field, the https://xxxxxxxxx.accounts.ondemand.com/saml2/idp/sso/xxxxxxxxx.accounts.ondemand.com value is cutted, it doesn’t enter entirely. I try just with:

      https://xxxxxxxxx.accounts.ondemand.com/saml2
      https://xxxxxxxxx.accounts.ondemand.com/saml2/idp/sso

      But the calling throw ajax on my mobile app doesn’t work. My ajax:

      $.get("https://mobile-xxxxxxxx.dispatcher.hana.ondemand.com/userapi/currentUser").done(function(results) {
        alert("success" + data);
      });

      I receive this HTML response by SAML IDP:

      ...
      <p><script language="javascript">document.write("Please wait ...");</script></p>
      
      <noscript>
       <p>Note: Your browser does not support JavaScript or it is turned off. Press the button to proceed.</p>
      </noscript>
      
      <form method="post" action="https://xxxxxxxx.accounts.ondemand.com/saml2/idp/sso/xxxxxxxx.accounts.ondemand.com"><input type="hidden" name="SAMLRequest" value="PEF1dGhuUmVxdWVzdCB4bWxucz0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOnByb3RvY29sIiB4bWxuczpuczI9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDphc3NlcnRpb24iIHhtbG5zOm5zMz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC8wOS94bWxkc2lnIyIgeG1sbnM6bnM0PSJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGVuYyMiIEFzc2VydGlvbkNvbnN1bWVyU2VydmljZVVSTD0iaHR0cHM6Ly9tb2JpbGUtYTM1NWU5ZThkLmRpc3BhdGNoZXIuaGFuYS5vbmRlbWFuZC5jb20vdXNlcmFwaS9jdXJyZW50VXNlciIgRGVzdGl.....+"/><input type="hidden" name="RelayState" value="oucrsjoxphifayttvbfrejmrg"/><noscript><input type="submit" value="Continue"/></noscript>
      </form>

      Could you help me please?

       

      Thanks,

      Luca

       

      Author's profile photo Jamie Cawley
      Jamie Cawley
      Blog Post Author

      Can you please create a new post in the Questions and Answers marked with the appropriates tags for you inquiry?

      Regards,

      Jamie

       

      Author's profile photo Ajay Gupta
      Ajay Gupta

      Hello Luca,

      It would be great if could please share how was it resolved.
      I am facing the same issue.

      Regards,
      Ajay

      Author's profile photo Greg Carino
      Greg Carino

      Hi Jamie,

       

      Thanks for the very useful blog.

      Would you know how to consume the same API using the SCP iOS SDK?

       

      Cheers,

      Greg