Select to view content in your preferred language

authenticated data extraction services?

2086
17
01-28-2011 09:27 AM
JonFisher
Emerging Contributor
I have an anonymous Data Extraction task up and running, and am calling it from FlexViewer 2.2 with the DataExtract widget with no trouble. However, in addition to this task, I want a separate authenticated task that will include sensitive data. My hope was that I can use tokens just like when I connect to secure map services via the viewer, but when I set <dataextractionservice> to https://<mysecureserverpath>/rest/services/TNC_internal/core_data_extract_auth/GPServer?token=<mytoken>
and try to call it via the viewer it doesn't work. I'm using the same token I use to connect to the secure map services (which are in the same folder as the secure GP service), and I'm accessing it via the same server / identifier.

Has anyone else tried this, either successfully or unsuccessfully?
Tags (2)
0 Kudos
17 Replies
MehulChoksey
Esri Contributor
Could you capture REST Request/response  using firebug/fiddler etc. to see whats going on?
0 Kudos
JonFisher
Emerging Contributor
Could you capture REST Request/response using firebug/fiddler etc. to see whats going on?


Good idea. From firebug it looks like instead of going to:
https://mapstest.tnc.org/ecadpubtestanon/rest/services/TNC_internal/core_data_extract_auth/GPServer?...<token> (which works fine when pasted into a browser) it's going to :
https://mapstest.tnc.org/ecadpubtestanon/rest/services/TNC_internal/core_data_extract_auth/GPServer?...<token>?f=json (which in a browser goes to a login page).

the same thing appears to be happening in the app, somehow the extra ?f=json is making it want a login so it's redirected to https://mapstest.tnc.org/ecadpubtestanon/rest/login?redirect=https%3a%2f%2fmapstest.tnc.org%2fecadpu...<token>%3ff%3djson

This seems odd to me, since the identifier was just set for mapstest.tnc.org (I have also tried tokens for http://mapstest.tnc.org and https://mapstest.tnc.org with the same result).
0 Kudos
MehulChoksey
Esri Contributor
Thanks for reporting this bug.This will be fixed in next release of the viewer.
You can do following:
1. Configure Proxy page
2. If you are working with the source,
Modify following code in DataExtractWidget from:
if (useProxy && configData.proxyUrl)
                    {
                        gpService.url = configData.proxyUrl + "?" + gpURL + "?f=json";
                        gp.proxyURL = configData.proxyUrl;
                    }
                    else
                    {
                        gpService.url = gpURL + "?f=json";
                    }


To:
 gpService.url = gpURL;
                    if (gpURL.indexOf("?") != -1){
                        if (gpURL.indexOf("f=json") == -1)
                        {
                            gpService.url = gpService.url + "&f=json"    
                        }
                    }else
                    {
                        gpService.url = gpService.url + "?f=json"
                    }
                    
                    if (useProxy && configData.proxyUrl)
                    {
                        gpService.url = configData.proxyUrl + "?" + gpURL;
                        gp.proxyURL = configData.proxyUrl;
                    }
0 Kudos
JonFisher
Emerging Contributor
Thanks for the new code! However, I'm still having trouble. The link produced now goes to an "invalid token" page. The new code still changes the link in the same way (e.g. https://mapstest.tnc.org/ecadpubtestanon/rest/services/TNC_internal/core_data_extract_auth/GPServer?...<token> to https://mapstest.tnc.org/ecadpubtestanon/rest/services/TNC_internal/core_data_extract_auth/GPServer?...<token>&f=json), but now instead of being prompted to login I'm told the token is invalid (even though the link with token works without the &f=json).

I haven't set up the proxy page yet, I haven't needed one before since we have a crossdomain.xml file. Is the proxy required for this to work (as opposed to a best practice), and if so should I just follow the instructions at http://help.arcgis.com/en/webapi/flex/help/index.html#proxy.htm?

thanks again,

Jon
0 Kudos
MehulChoksey
Esri Contributor
Thats strange that your service doesnt like f=json.
Lets try to make it work without proxy first.

could you try updating your original code from:
if (useProxy && configData.proxyUrl)
                    {
                        gpService.url = configData.proxyUrl + "?" + gpURL + "?f=json";
                        gp.proxyURL = configData.proxyUrl;
                    }
                    else
                    {
                        gpService.url = gpURL + "?f=json";
                    }

  


To:
if (useProxy && configData.proxyUrl)
    {
        gpService.url = configData.proxyUrl + "?" + gpURL;
        gp.proxyURL = configData.proxyUrl;
    }
 gpService.url = gpURL; 
0 Kudos
JonFisher
Emerging Contributor
Thanks for your continued patience. I did realize that I was using the wrong URL (I was appending the token to /GPServer rather than GPServer/Extract Data Task. However, fixing that didn't change the behavior. The default code doesn't work, the second set of code you provided results in an "invalid token" message, and in the third set of code firebug shows that the correct URL is retrieved successfully, but the application stops after the page is called and there's still no checkboxes of data layers. Incidentally, the most recent code (which eliminates the ?f=json) also breaks the widget for an anonymous service for me, whereas the other sets of code worked fine for an anonymous service.

Perhaps I should wait until I have a public-facing AGS10 server (it should be ready in just over a week) so that I can create an example service with token (but non-sensitive data) and post it here? thanks again for your help,

Jon
0 Kudos
MehulChoksey
Esri Contributor
Having a public facing website would be easier to troubleshoot...
0 Kudos
JonFisher
Emerging Contributor
I've figured out that this problem only occurs in Firefox, the data download with token works fine in IE and Chrome (and viewing map services & search widget work fine in all 3). I created a test secure service (using public data only) along with token from a dummy user here:
https://maps.tnc.org/ecadpubprodanon/rest/services/testextract_auth/GPServer/Extract Data Task?token...

That link works in firefox, IE, and chrome.

However, https://maps.tnc.org/ecadpubprodanon/rest/services/testextract_auth/GPServer/Extract Data Task?token... only produces an error in firefox: "{"error":{"code":498,"message":"Invalid token","details":[]}}". In IE or Chrome you get the expected details: "{"name":"Extract Data Task","displayName":"Extract Data Task",etc etc etc".

To help test, I set up a basic web map here:https://maps.tnc.org/extracttest/. Try it in firefox and you get an invalid token error, but it works in IE & Chrome.

Does that help troubleshoot? Any idea what Firefox is doing wrong?
0 Kudos
JonFisher
Emerging Contributor
Stranger yet, I find that copying and pasting the links I posted work as I described, but clicking them via this link does not work. In other words, copy and paste this :
https://maps.tnc.org/ecadpubprodanon/rest/services/testextract_auth/GPServer/Extract%20Data%20Task?token=J7xH0dk8hRXP5Bq_YQevwSX7P92kPPLK25IE0dxYDIYp6SFZFJC6lJfTkgDLDrPDorpDog7ohIUV-rLV4QfnFg..
and it works differently from this: https://maps.tnc.org/ecadpubprodanon/rest/services/testextract_auth/GPServer/Extract%20Data%20Task?t...

Maybe the browser is incorrectly parsing characters like / and space? It also seems that the forum automatically assumes that the trailing . characters aren't part of the link, which could be the trouble.
0 Kudos