Hi I am looking for some help with an irule that can call out to an api
I been pulled into a project that is replacing a mobile app. For the project they need f5 to do the following :
- listen for a http request on a vs and extract the bearer token fro that request
- append the token to an api query and send it to another application
- parse the json response for query and capture the username sent back
- Replace header values in the original request and send it to the backend servers on the vs.
Basically replacing the bearer token with other headers. This is what I came up with as a skelton but having trouble on how to make an api call from an irule and parse the json response. Also the vendor mentioned that a solution with these steps have been implemented at other clients who use Netscaler. I am waiting for tech documentation on the netscaler solution to see if can help me out.
when when HTTP_REQUEST {
if {[HTTP::uri match "/Auth/OAuth2/CREATESESSION"] and [string tolower [HTTP::header Authorization]] contains "bearer"} {
#Extract the bearer token from the auth header an dsave it to a variable
set bearer_token [string map {bearer ""} [string to lower[HTTP::header value Authorization]]
#Send an api query to https://TBD/api/scim/Me?attributes=userName that appends the bearer token to the end
set api_endpoint "https://TBD/api/scim/Me?attributes="
append api_endpoint $bearer_token
??? --> how to call a api from irule
#Parse the json response and retrieve the username.
??? --> set euid [parse json for username key pair ]
#Rewrite the original HTTP request replace the User ID in the header with the new user ID and update the Authorization header to static basic header with auth credentials.
HTTP::header replace Authorization ""
HTTP::header replace User-ID $euid
HTTP::header replace User-IDType "SYSTEMLOGIN"
}
}
irules is not good at parsing JSON key value in HTTP Payload, Initiating HTTPS connections on irules' sideband is also cumbersome
I suggest you use irules and cooperate with iRulesLX to initiate a sideband https connection using node.js,Node.js can use its built-in JSON library to handle JSON, which is very advantageous