Okta Java SDK - Set Request header/Retrieve Response header

We are using Okta Java SDK, and we have a requirement to set the client ip address (x-forwarded-for) and to log the response header (x-forwarded-for) return by Okta.

But I don’t see any option to either set the header or retrieve the response header using SDK. How can I implement this or is there any way to customize the okta Client to achieve this ?

Update:
For setting the header, there is an option as below, but that would mean not using the API objects (User, Factor, Group etc)

oktaClient.http().addHeaderParameter("x-forwarded-for", "ip-address");

I am also interested in setting the “x-forwarded-for” header for API requests through the Java API. Abta, did you find anything on this topic?

Hello!

If you are using Okta’s Java Auth SDK, it has built in support: GitHub - okta/okta-auth-java: okta-auth-java

If you are using the Management SDK (okta-sdk-java), you would need to use the “call other endpoints” technique: GitHub - okta/okta-sdk-java

You can still use the API objects, but you will need to set in the URLs, for example, something like:

User user = client.http()
    .setBody(yourUserObject)
    .addHeaderParameter("x-forwarded-for", "ip-address")
    .post("/api/v1/users/<user-id>", User.class);

(this is a combination of cut/paste and memory, so it might need to be tweaked a little)

If you would like to see built in support for this please open a feature request on the GitHub repo: Issues · okta/okta-sdk-java · GitHub

Thanks very much for that code sample. I think I will request it as a feature in the Okta SDK project.

Edit: I have opened issue Add ability to set x-forwarded-for header without using .http() "other requests" method · Issue #739 · okta/okta-sdk-java · GitHub. Thanks again for your help and guidance, bdemers.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.