cancel
Showing results for 
Search instead for 
Did you mean: 

Processing POST Batch Data in SAP CPI via ODATA using OAuth2 Authorization Code

sachin999940
Participant
816

Hi everyone,


I have a requirement where I have to use oauth2 authorization code to POST batch data in SAP CPI.
I found many example using HTTP. Kindly help me achieving it using ODATA.

Thanks and Regards
Sachin Kumar Singh

Accepted Solutions (1)

Accepted Solutions (1)

bdBais
Explorer

Summarized:

1) Create on credentials the OAuth 2 working credentials, you will need authorization redirect url do that, normaly creation of Auth need this address to authorize your application to ask auth code,that.

2) Create an Header Authorization with the token recovered by groovy script (this ask to vault which authorization code it received from auth url in step 1).

import com.sap.gateway.ip.core.customdev.util.Message;
import com.sap.it.api.securestore.SecureStoreService;
import com.sap.it.api.securestore.AccessTokenAndUser;
import com.sap.it.api.ITApiFactory;


def Message processData(Message message) {

    SecureStoreService secureStoreService = ITApiFactory.getService(SecureStoreService.class, null);
    AccessTokenAndUser accessTokenAndUser = secureStoreService.getAccesTokenForOauth2AuthorizationCodeCredential("iftonoapp_IAS_AuthCode");
    String token = accessTokenAndUser.getAccessToken();

    message.setHeader("Authorization", "Bearer "+token);

    return message;
}

3) Call your OData/Http without authentication method (None), with request Header: Authorization on request of your API.

F.B.

sachin999940
Participant
0 Kudos

Hi Federico
I am getting the above error when doing authorizing. Can help me on this?

Thanks and Regards
Sachin Kumar Singh

Answers (2)

Answers (2)

CarlosRoggan
Product and Topic Expert
Product and Topic Expert

Hello,

OData is a protocol which is added on top of HTTP.
As such, I assume that there should be no difference wrt authentication/authorization (as long as it is supported by the target application)

You've already found the blog posts, so I think you can just go ahead and try it.

I have also a blog post with some explanation about "authorization code" flow, you might find it useful for your scenario:

https://blogs.sap.com/2023/08/24/sap-cloud-integration-how-to-call-ias-based-application-from-iflow-...

bdBais
Explorer
0 Kudos

@Sachin Kumar Singh

You receive that error from credential owner, they must put your redirect address on access list associated with client_id and secret you are using.

Federico Bellizia

sachin999940
Participant
0 Kudos

Thanks bellizia_capgemini

We are new in this space, would you mind to give screen shots where we have to maintain this

Regards
Sachin Kumar Singh