Skip to Content
0

How pass the JWT token valuse in the REST receiver adapter header dynamically

Nov 17, 2016 at 09:44 AM

848

avatar image
Former Member

Dear experts,

I have a requirement where i need to call the REST API using JWT token authentication which needs to be passed in the header of the request. JWT token will expires on every 15 mins. Please provide your thoughts.

Thanks,

Pavan T

10 |10000 characters needed characters left characters exceeded
Former Member

Hi Experts,

Used Below Java mapping to fulfill my requirement.

public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException { try{ String inputPayload = convertInputStreamToString(transformationInput.getInputPayload().getInputStream()); String outputPayload = inputPayload.replaceAll("_OUTPUT", "OUTPUT"); transformationOutput.getOutputPayload().getOutputStream().write(outputPayload.getBytes()); transformationOutput.getOutputPayload().getOutputStream().flush(); }catch(Exception ex){ throw new RuntimeException(ex.getMessage()); } } public String convertInputStreamToString(InputStream in) { StringBuffer sb = new StringBuffer(); try { InputStreamReader isr = new InputStreamReader(in); Reader reader = new BufferedReader(isr); int ch; while ((ch = in.read()) > -1) { sb.append((char) ch); } reader.close(); } catch (Exception localException) { } return sb.toString(); }

Thanks,

Pavan T

0
Former Member

Hi Pavan,

Why do we require Java mapping here as we can pass Custom HTTP headers in REST receiver adapter.

As far I know, we need to pass the combination of Base64 Encoded string of "header.payload.signature" to HTTP headers.

We can read the values with Xpath Expression from input payload and can set them to HTTP headers.

Let me know your Usecase as I have a similar requirement REST to PI to REST with JWT authentication.

Thanks!

Best Regards,

Sachin Jangir

0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Vadim Klimov Nov 17, 2016 at 03:04 PM
0

Hello Pravan,

In PO 7.31 SP15 / PO 7.4 SP10, REST adapter was enhanced with functionality for setting custom HTTP headers (refer to https://blogs.sap.com/2015/04/14/pi-rest-adapter-define-custom-http-header-elements/ for details and examples). A part which is not available there and which will have to be custom developed (within mapping logic or as a custom adapter module) or purchased from 3rd party, is acquisition of JWT from the authorization server, its parsing and placement of an access token value in dynamic configuration attribute (which value can then be used when setting custom HTTP header using the referred functionality of REST adapter).

Regards,

Vadim

Share
10 |10000 characters needed characters left characters exceeded