Forum Discussion

sricharan61's avatar
Dec 09, 2019

How to use string map to set and insert a part of the URI to the destination redirect irule

How to use string map or other TCL methods to set and insert a part of the URI to the destination redirect irule. I have a requirement to look for a URI path in a request and use that to set a URI path for the redirect endpoint we would redirect the client to. A part of the redirect URI is predefined and the later part of the redirect URI would have to filled out on the go based on the contents initial clients URI path. I have the clients request come in as

1)

https://www-xxxxxxx.com/logout-apm?post_logout_redirect_uri=/includes/logged_out.aspx

 

The end result of the redirect endpoint should be

2)

https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri=https://www-xxxxxxx.com/includes/logged_out.aspx

 

the the post_logout_redirect_uri part of 2)'s URI should be formed on the fly by F5 by learning 1)'s host name www-xxxxxx.com and the rest of the URI emitting the "logout-apm" from it.

 

I thought we could use string maps to establish this, so i am trying something with that but without success, here is where i am at right now

 

when HTTP_REQUEST {

set host [HTTP::host]

set uri [HTTP::uri]

if 

{$uri contains

"/logoutapm"} {

set HTTP::uri [string

map {logoutapm?post_logout_redirect_uri=/includes/logged_out.aspx

common/oauth2/v2.0/logout?post_logout_redirect_uri=https://$host/includes/logged_out.aspx} "logoutapm?post_logout_redirect_uri=/includes/logged_out.aspx"]

   HTTP::redirect

"https://login.microsoftonline.com/[HTTP::uri]"

   }

  }

 

trying to see if there is a better alternative to this approach, this syntax and logic are not giving the desired redirect endpoint.

 

4 Replies

  • Hi sricharan61,

    Do you have to use String Map?

    when HTTP_REQUEST {
    	if { [string tolower [HTTP::uri]] equals "/logout-apm?post_logout_redirect_uri=/includes/logged_out.aspx" } {
    		HTTP::redirect "https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri=https://[HTTP::host]/includes/logged_out.aspx"
    	}
    }
    • sricharan61's avatar
      sricharan61
      Icon for Cirrus rankCirrus

      Got it, i think actual issue i wanted to address is when in 1) we dont know what the URI path is as well.. except for the fact that it contains logout-apm?

      we dont know before hand what the pos_logout_redirect_uri exactly has as its value... like for now we do know /includes/logged_out.aspx is what the post_logout parameter in 1) is going to be so we are able to define it in the redirect URI directly. We want to be able to be in a position where F5 can actually learn that in real time as well and use it to populate part of the uri section in 2)

       

      • Enes_Afsin_Al's avatar
        Enes_Afsin_Al
        Icon for MVP rankMVP

        Can you try this?

        when HTTP_REQUEST {
        	if { [HTTP::uri] starts_with "/logout-apm" } {
        	    if { [HTTP::uri] contains "post_logout_redirect_uri" } {
            		set postLogoutValue [URI::query [HTTP::uri] post_logout_redirect_uri]
            		# log local0. "Logout Value: $postLogoutValue - Redirect Uri: https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri=https://[HTTP::host]$postLogoutValue"
            		HTTP::redirect "https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri=https://[HTTP::host]$postLogoutValue"
        	    }
            	else {
            	    # log local0. "logout uri not contains post_logout_redirect_uri parameter"
            	}
            }
        }