← Blog

Experiment: run Cloud Integration iFlows without authorization

How to expose an SAP Cloud Integration iFlow without authentication by putting SAP API Management in front, with the credentials in a key value map.

October 2, 2023 · 3 min read

Most of the times when you need to call a SAP Cloud Integration (CPI) iFlow in Integration Suite you will need a Servicekey. But what about the cases where it is not possible to use authentication.

If you have webhooks struggling with setting authentication or if you’re communicating with partners using AS2, this approach can streamline these interactions. And another perk, it lets you change the backend without a heads-up to your partners.

You can download the sample iflow here.

Start with the iFlow. Pick an iFlow to expose, set up its URL, and create a role allowing users to call this iFlow only.

An iFlow with an HTTPS sender at the address /ProtectedBy_API, using user role authorization

Create a Service Key. Head to your BTP cockpit, create a service key using the role, and grant access to the messaging API. Remember to use Grant type password. And then set the custom role into the roles section.

The service key configuration with the grant types client_credentials and password, and the role ProtectedAPI

Dive into API Management. Set up a credential store to keep the service key and use it in the API proxies. Don’t forget to select encrypt it before inserting the clientid and clientsecret into the values.

The encrypted key value map SAPCPIUser in API Management, with the entries protectuser and protectpass

Create an API Proxy. Use the CPI endpoint as the target and make sure the exposed URL conveys what this API is all about clearly.

Creating an API proxy in API Management with the Cloud Integration endpoint as the target URL

Add Policies to the Proxy. Once your API proxy is all set, it’s time to add the policies. Under the TargetEndPoint Preflow add the policy. The first policy to add is a key value map operation, and you need to link this to the KVM that you created earlier. It ensures everything is connected and running like a well-oiled machine. Because the KVM is encrypted the keys need to be using the prefix private.

The key value map operations policy that reads the user and password from SAPCPIUser
<KeyValueMapOperations mapIdentifier="SAPCPIUser" async="true" continueOnError="false" enabled="true" xmlns="http://www.sap.com/apimgmt">
    <Get assignTo="private.user" index="1">
       <Key>
          <Parameter>protectuser</Parameter>
       </Key>
    </Get>
    <Get assignTo="private.pass" index="1">
       <Key>
              <Parameter>protectpass</Parameter>
       </Key>
    </Get>
	<!-- the scope of the key value map. Valid values are environment, organization, apiproxy and policy -->
	<Scope>environment</Scope>
</KeyValueMapOperations>

Add Basic Authentication Policy. Next up, we’re adding a basic authentication policy. Use the variables picked out in the KVM and create a new request header authorization. It sets up the basic authentication needed to reach the backend of API management.

The basic authentication policy that encodes the user and password into the Authorization header
<BasicAuthentication async='true' continueOnError='false' enabled='true' xmlns='http://www.sap.com/apimgmt'>
 	<!-- Operation can be Encode or Decode -->
	<Operation>Encode</Operation>
	<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
 	<!-- for Encode, User element can be used to dynamically populate the user value -->
	<User ref='private.user'></User>
 	<!-- for Encode, Password element can be used to dynamically populate the password value -->
	<Password ref='private.pass'></Password>

 	<!-- Assign to is used to assign the encoded value of username and password to a variable. This should not be used if the operation is Decode -->
	<AssignTo createNew="false">request.header.Authorization</AssignTo>
</BasicAuthentication>

Under the Preflow you need to add some Traffic Management Policies to ensure the Cloud Integration is not overloaded. It can be spike, or some IP based policies.

The API Management policy editor with a spike arrest policy in the proxy endpoint preflow

Test it Out! Finally, time to call this external endpoint! Check and see if it’s producing the right result, and voilà, you’re all set!

Postman calling the API proxy without authorization and getting 200 OK with "Cloud Integration was here"

I hope you can see how this can simplify your setup.

This post covers these products

More from the blog

All posts →

See this working in your landscape

No credit card required.

Integration cost calculator →

Start your free trial

No credit card required

Try Figaf DevOps Suite free for 30 days. It takes less than an hour to get started, and we send everything you need by email.

Join our newsletter

Get the latest about Figaf, SAP and anything relevant to SAP integration, every week in Figaf Weekly.