Apigee Edge not detecting query parameter

I am using Apigee edge free version to create API proxy which would fetch user profile from Facebook.Using the below url , i get the access token.

https://www.facebook.com/dialog/oauth?response_type=token&redirect_uri={Another.proxy.on.APigee.Edge....

The above url sends me a redirect uri(another API proxy on Apigee edge) and an access token.I have added extract query param to extract the access token from the query param.

The problem is the access token is being sent as https://{redirect uri}?#access_token={accesstoken}.

Apigee is not detecting the query parameter as there is # at the beginning. Hence my extract query param is giving error "{"fault":{"faultstring":"Unresolved variable : queryinfo.token","detail":{"errorcode":"entities.UnresolvedVariable"}}}"

Please suggest on how to fix this.

0 2 1,064
2 REPLIES 2

Hi @Rajeev S,

You can alternatively use Javascript policy to extract the query-param as redirect_uri as a whole, and then use the substring operation on the value obtained from redirect_uri query param.

The request sent to the sample API proxy is as follows -

http://nishamallesh-test.apigee.net/extract-variables?response_type=token&redirect_uri=http%3A%2F%2F...
redirect_uri - http://test.com?#access_token=token

encoded string - http%3A%2F%2Ftest.com%3F%23access_token%3Dtoken

The following Javascript policy works (tested).

 var redirect_uri=context.getVariable("request.queryparam.redirect_uri");

 var token_string=redirect_uri.split('#')[1];

 var token= token_string.substring(token_string.indexOf('=')+1);

Note : I tried testing the Url against postman and what I noticed was, the Url fragment was chipped after #.

Perhaps, that was the reason for the error - entities.UnresolvedVariable.

It is a better way to use encodeUri() method to encode the redirect_uri fragment https://{redirect uri}?#access_token={accesstoken}.


Hope this helps, thank you!

@nisha mallesh Thanks for your reply. Unfortunately as you said the value after #( called URL fragment) is never sent to the API proxy, but it is stripped at the browser/client side. So there is no easy way of doing it.

Have you worked on integrating with Facebook from APigee? I would like to know if there is any other way of getting user access token to retrieve user profile from Graph API.

Thanks,

Rajeev S