cancel
Showing results for 
Search instead for 
Did you mean: 

REST Adapter Dynamic Token Authentication

Former Member
0 Kudos

Hi Experts,

We have requirement for REST interface where we need to call dynamic token authentication and GET and POST results through the REST Adapter

It would be great if you share the right document/link for dynamic token authentication.

we are using SAP PI 7.4 for integration.

Thank you in Advance,

Regards,

Krushi.

Accepted Solutions (0)

Answers (3)

Answers (3)

0 Kudos

We cannot use Java mapping as the GET and POST call must happen in the same session and we have to pass the csrf token and cookie in the header of the post call. We have to implement this using adapter module and udf for dynamic configuration.

Former Member
0 Kudos

Hi Fedrick,

Thank you for your prompt response. Yes indeed we need to token authenticate at receiver side. do we need to create a function library or UDF in mapping. can you please Advise?

Regards,

Krushi.

peakMeissner
Active Participant
0 Kudos

Hey krushi.nenavath2 ,

if you want to proceed using an UDF I'd recoment the following blog:

https://blogs.sap.com/2012/11/19/how-to-create-user-defined-function-for-message-mapping-using-nwds/

I'd hook the UDF function into the first graphical mapping step.

If you need futher information on the API functionallity check out the SAP JavaDocs based on your EAI setup

Regards.

Frederick

peakMeissner
Active Participant
0 Kudos

Hi,

do you need to authenticate the application on the sender or receiver side? If you need to authenticate the application at the receiver side you could implement a JavaMapping that authenticates the client at the server and writes the token to the header of the receiver message. You could use the following mapping skelleton to continue.

package com.xxx.aii.mapping;

import java.io.InputStream;
import java.io.OutputStream;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;

public class MessageMapping extends AbstractTransformation {

	@Override
	public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {
		try {
			InputStream is = transformationInput.getInputPayload().getInputStream();
			OutputStream os = transformationOutput.getOutputPayload().getOutputStream();

			/**
			 * TODO:
			 * - copy payload to the TransformationOutput object
			 * - retrieve token from the external server
			 * - write the token to the header of the TransformationOutput
			 */

		} catch (Exception exception) {
			getTrace().addDebugMessage(exception.getMessage());
			throw new StreamTransformationException(exception.toString());
		}
	}

Binod_Thakur
Participant
0 Kudos

Hello Frederick,

Thanks for your post. I always like to use java mapping instead of UDF. I have created the logic for generate the token, but don't know how to pass that token to the header filed in REST adapter.

I have a scenario where i have to use rest adapter in both side sender (REST Pooling) and receiver.

As you have mentioned java mapping for receiver side, can you please tell me how to pass access_token in header of the TransformationOutput?

And for sender REST Pooling i have to authenticate as well, Is java mapping will work for sender rest polling as well ? OR I have to use UDF?

If UDF then please send me the sample code for UDF to generate token and pass it to header


Thanks,

Binod