on 2023 Nov 27 7:07 AM
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
Request clarification before answering.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
64 | |
8 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.