Unable to decode queryparam

We need to decodeURI for redirect uri & remove any empty query params from the request.

Issue we are facing is it does shows as decoded but when the final query param which it generates still have the encoded redirect uri. Used below JS for testing but didn't seems to be working.Please suggest.

var count = context.getVariable('request.queryparams.count');
var queryString = context.getVariable('request.querystring');
var queryStringNew = ""
var queryParams = queryString.split("&");
for (var i = 0; i < count; i++) 
{  
var queryParam = queryParams[i].split("=");  
   if (queryParam[1] === "") 
{    
 context.removeVariable("request.queryparam." + queryParam[0]); 
 }     
if (queryParam[0] == "redirect_uri")
{  
print("OLD-->>" + queryParam[1] + "NEW-->>" + decodeURIComponent(queryParam[1]));  
context.setVariable("request.queryparam." + queryParam[0], decodeURIComponent(queryParam[1]));  
}
}
0 6 1,728
6 REPLIES 6

Hi

I'm not clear on the problem.

Can you tell me:

1. what is your input? Specifically. Rather than describing it, show me.

2. What results do you actually see? Better not to describe the results, just tell me the actual results you see.

3. What results do you EXPECT to see? Better to just SHOW ME.

Example:

1. I am passing this: foo=7&bar=398398393

2. I am expecting this: foo=17&bar=none

3. I am getting this: foo=bar&17=9287389e47

Sure Dino.

Below are the details:

If we pass below input in queryparam

https://test-apigee.com/test?redirect_uri=https://test.apigee.com/testpsd2&client_id=teste324323344&...

It is getting converted to below and shows as request.querystring

redirect_uri=https%3A%2F%2Ftest.apigee.com%2Ftestpsd2&client_id=teste324323344&response_type=code&scope=accounts

java script print shows it gets converted as below but the final query string with decoded value for redirect uri is what we are looking.

OLD-->>https%3A%2F%2Ftest.apigee.com%2Ftestpsd2NEW-->>https://test.apigee.com/testpsd2

Still checking but am I missing something here?

ok, I understand what you've written.

You said you "pass in" the full URL. Whatever you are using to pass in that data is url-encoding the query parameter called "redirect_uri". This is correct behavior. This is required by the HTTP standard, RFC 2616.

It looks to me that you have JS code that is decoding the redirect_uri query param.

It looks to me that the decoding of that query parameter is succeeding - in fact the result is the correctly decoded parameter: https://test.apigee.com/testpsd2

At this point, I'm still not clear on the problem you are having.

You wrote:

but didn't seems to be working.

What, specifically, is not working? I don't understand.

Sure.

say we have 4 query params - redirect uri,client id,response_type and scope

redirect uri->https%3A%2F%2Ftest.apigee.com%2Ftestpsd2
client_id= <<empty>>
response_type=code
scope=accounts

now in redirect uri we see encoded string which needs to be decoded

remove any empty query params(as client_id as shown above).

final list of query params string should have removed empty query params(client_id) & decoded redirect uri,response_type,scope

final list:

redirect uri->https://test.apigee.com/testpsd2
response_type=code
scope=accounts

Hope this is clear.

ok, thanks. I'm clear on what you want.

I think your JS code accomplishes that. I just tested it, and it is doing what you want, for me.

What is the problem you are encountering?

What specifically is not working?

Can you attach the proxy if you have created? Want to see the final query param which has the decoded redirect uri and removed any empty queryparams.