1

I'm using JavaScript API 3.24 for reference. I want my application to automatically allow users to access secured services based on background authentication via a token (this way they don't need to login). I have reviewed the documentation and many questions here, but I just can't seem to get it to work. Sorry for the length of this post, but I want to explain fully what I have tried.

I've secured one geoprocessing service called Habitat Management. It is located in the HabitatManagement folder, the service is titled HabitatManagement, and it contains a geoprocessing task called HabitatManagement. Essentially, the url for the secured service looks like this:

https://www.mydomain.com/myServer/rest/services/HabitatManagement/HabitatManagement/GPServer/HabitatManagement

The actual web mapping application resides inside of a .NET application. The URL of the .NET application is this:

https://www.mydomain.com/appName

The actual web map url is this:

https://www.mydomain.com/appName/HabitatMap/HabitatJSMap

I have my proxy config file set up like so:

<ProxyConfig allowedReferers="*"
             mustMatch="false"
             logFile="proxyLog.txt"
             logLevel="Warning">
    <serverUrls>
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatManagement/HabitatManagement/GPServer/HabitatManagement"
                  username="username"
                  password="password"
                  matchAll="true"/>
    </serverUrls>
</ProxyConfig>

I have the proxy JS code like this:

urlUtils.addProxyRule({
                urlPrefix: "https://www.mydomain.com",
                proxyUrl: "https://www.mydomain.com/appName/proxy/proxy.ashx"
            });

If I go to the proxy page following this URL:

https://www.mydomain.com/appName/proxy/proxy.ashx

It works as expected, it says "Config File: "OK" Log File: "OK""

When I test this URL, it shows the login screen for my REST services, even though the token should be passing the username and password so I can see the services, right? That's issue #1 that I don't understand.

https://www.mydomain.com/appName/proxy/proxy.ashx?https://www.mydomain.com/myServer/rest/services/HabitatManagement/HabitatManagement/GPServer/HabitatManagment

Additionally, when I go the web map and try to access the service, it still makes me login with this message:

Please sign in to access the item on https://www.mydomain.com/myServer (HabitatManagement/HabitatManagement)

If I login, things work fine - it appears the token is generated and appended to the URL as it should be.

I have also tried to change my serverURL to something very general with no luck. Ideally, the serverURL would be more specific than this as there are some services we have that don't require authentication thus do not need to run through a proxy. This just takes me to the login page for my REST services too.

<serverUrl url="https://www.mydomain.com"
                  username="username"
                  password="password"
                  matchAll="true"/>

I'm not sure if my proxy is located in the wrong spot in my .NET application, or if my referrer URL is messed up, or if my serverURLs are messed up. How do I access my secured services using the proxy?

0

Well...I finally got it working. I still don't know what I did to get it to work but on the 500th try it did. The only things I think I changed between the last try and this one was updating the path to the proxy log file in the proxy's web.config file. I also fixed my one GP service that still had a URL that ended in /uploads/upload to be more general and just ending in /GPServer like the other one (see original post). I hadn't changed it earlier because I haven't been testing submissions with that service, I was only testing the habitat management one. Maybe that's what fixed it? I also republished my app, obviously.

Here's the final code:

JS

urlUtils.addProxyRule({
            urlPrefix: "https://www.mydomain.com",
            proxyUrl: "/appName/proxy/proxy.ashx"
        });

proxy.config

<ProxyConfig allowedReferers="https://www.mydomain.com/*"
             mustMatch="true"
             logFile="proxyLog.txt"
             logLevel="Warning">
    <serverUrls>
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatManagement/HabitatManagement/GPServer"
                 username="username"
                 password="password"
                 matchAll="true"/>
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatMonitoring/HabitatData/MapServer"
                 username="username"
                 password="password"
                 matchAll="true" />
      <serverUrl url="https://www.mydomain.com/myServer/rest/services/HabitatMonitoring/HabitatClassification/GPServer/"
                 username="username"
                 password="password"
                 matchAll="true" />
    </serverUrls>
</ProxyConfig>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.