Forum Discussion

sricharan61's avatar
Jan 15, 2020

I am trying to pick out a string of a decrypted JSON web token to set some paramters in it as variables that i can later use to refer in a custom HTTP header. So, the sample token i have is

I am trying to pick out a string of a decrypted JSON web token to set some paramters in it as variables that i can later use to refer in a custom HTTP header.

So, the sample token i have is

 

aud:0000000x-0000-0000-x000-000000000000 iss:https://abc.niudots.bla/05544227-bag3-xxxx-bxxx-xxc48xx9xxx1/ iat:asdqwev255 nbf:1231233255 exp:15734555 acct:0 acr:9 aio:412345678901234567890123456789012345678901234567890A amr:wxx {app_displayname:Fx xxx-IP xxx xxxxx AD integration} appid:xxxxxxxx-xxxx-xxxx-bxxx-ddqweqrgqac appidacr:6 family_name:xxxxx given_name:xxxxxxxxx in_corp:xxxx ipaddr:1xxxxxxxxxx name:Rache { SriCharan} oid:156e4752-c00a-4bd7-88f4-2ea93b9c9abc onprem_sid:S-1-5-21-2295680679-3582917459-1200463588-131619 platf:3 puid:1xxxxxxxxxxxxxxxA {scp:Directory.Read.All email openid profile User.Read User.Read.All} sub:vxxxxxxxV_qMxxxxxxxxxtWl5_b-2xxxxxxxxZn_mwYXHc tid:02f85842-fff3-4d05-b300-ebc48a392de1 unique_name:x123456@xxxxxxxxxxxxxx.com upn:c142652@xxxxxxxxxxxxxx.com uti:PxxxxxxxxxxxxxxxxxxAQ ver:5.0 xms_st:sub:xxxxxxxxxxxxxxxxxxP6

 

 

I need to pick out two values from this token.

The

OID and the

TID

and set them as two new custom HTTP headers and pass that onto the backend servers.

Is there a way we can set the values in OID and TID as custom variables

1 Reply

  • Hi

    Try something like this....

    when HTTP_REQUEST {
      if {[HTTP::method] eq "POST"}{
        if {[HTTP::header "Content-Length"] ne "" && [HTTP::header "Content-Length"] <= 1048576}{
          set content_length [HTTP::header "Content-Length"]
        } else {
            set content_length 1048576
        }
        if { $content_length > 0} {
          HTTP::collect $content_length
        }
      }
    }
    when HTTP_REQUEST_DATA {
        set payload [HTTP::payload]
      set oid [findstr $payload "oid:" 4 " "]
      set tid [findstr $payload "tid:" 4 " "]
      HTTP::header insert OID $oid
      HTTP::header insert TID $tid
      log local0. "OID = $oid - TID = $tid"
    }